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]

[C++ PATCH for 3.3/trunk, committed] Fix PR9970, a regression


Hi

The PR c++/9970 exposes a bug inside 'duplicate_decls'.
The DECL_THUNKS and DECL_FRIEND_CONTEXT share the same
field in a decl node.  For virtual functions, it's a
DECL_THUNKS while for friend functions, it's a 
DECL_FRIEND_CONTEXT.  These two have to be handled
differently in 'duplicate_decls'.

- For DECL_THUNKS, we have to copy this from OLDDECL to 
  NEWDECL.  The current 'duplicate_decls' does this but
  lacks a check to make sure we are really dealing
  with virtual functions.

- For DECL_FRIEND_CONTEXT, we have to copy from NEWDECL to
  OLDDECL.  The 'memcpy' near the end of 'duplicate_decls' 
  does the job.

The patch below fixes 'duplicate_decls' to have the
correct behavior mentioned above.  This is a regression
in 3.3 and trunk.

Bootstrapped and tested on i686-pc-linux-gnu.  Patch
committed to 3.3 and trunk as obvious.

--Kriang


2003-03-09  Kriang Lerdsuwanakij  <lerdsuwa at users dot sourceforge dot net>

	PR c++/9970
	* decl.c (duplicate_decls): Only copy DECL_THUNKS for virtual
	functions.

2003-03-09  Kriang Lerdsuwanakij  <lerdsuwa at users dot sourceforge dot net>

	PR c++/9970
	* g++.dg/lookup/friend1.C: New test.


diff -cprN gcc-33-save/gcc/cp/decl.c gcc-33-new/gcc/cp/decl.c
*** gcc-33-save/gcc/cp/decl.c	Tue Mar  4 21:11:48 2003
--- gcc-33-new/gcc/cp/decl.c	Sun Mar  9 19:20:38 2003
*************** duplicate_decls (newdecl, olddecl)
*** 3637,3643 ****
  	  DECL_BEFRIENDING_CLASSES (newdecl)
  	    = chainon (DECL_BEFRIENDING_CLASSES (newdecl),
  		       DECL_BEFRIENDING_CLASSES (olddecl));
! 	  DECL_THUNKS (newdecl) = DECL_THUNKS (olddecl);
  	}
      }
  
--- 3637,3646 ----
  	  DECL_BEFRIENDING_CLASSES (newdecl)
  	    = chainon (DECL_BEFRIENDING_CLASSES (newdecl),
  		       DECL_BEFRIENDING_CLASSES (olddecl));
! 	  /* DECL_THUNKS is only valid for virtual functions,
! 	     otherwise it is a DECL_FRIEND_CONTEXT.  */
! 	  if (DECL_VIRTUAL_P (newdecl))
! 	    DECL_THUNKS (newdecl) = DECL_THUNKS (olddecl);
  	}
      }
  
diff -cprN gcc-33-save/gcc/testsuite/g++.dg/lookup/friend1.C gcc-33-new/gcc/testsuite/g++.dg/lookup/friend1.C
*** gcc-33-save/gcc/testsuite/g++.dg/lookup/friend1.C	Thu Jan  1 07:00:00 1970
--- gcc-33-new/gcc/testsuite/g++.dg/lookup/friend1.C	Sun Mar  9 19:27:40 2003
***************
*** 0 ****
--- 1,15 ----
+ // { dg-do compile }
+ 
+ // Origin: <matz at suse dot de>
+ 
+ // PR c++/9970: In-class friend function definition after
+ // declaration lexical scope problem.
+ 
+ void f();
+ struct X
+ {
+   enum { k = 1 };
+   friend void f() {
+         char a[k];
+   }
+ };


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