C++ PATCH: Fix another destruction problem

Mark Mitchell mark@codesourcery.com
Sun Oct 22 23:36:00 GMT 2000


This patch fixes a test-case where there more destructor calls than
constructor calls.  Ugh. 

The fix is not intuitive, and I'm not 100% sure of its correctness,
even though it passes all tests on i686-pc-linux-gnu.

This code (i.e., the code that handles various kinds of conversions,
especially in the context of function calls), has gotten pretty
horrific.  Probably due for some major cleanups after GCC 3.0.

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

2000-10-22  Mark Mitchell  <mark@codesourcery.com>

	* call.c (standard_conversion): Use RVALUE_CONVs for all
	expressions that satisfy lvalue_p, not just those that satisfy
	real_lvalue_p.

Index: cp/call.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/call.c,v
retrieving revision 1.231
diff -c -p -r1.231 call.c
*** call.c	2000/09/19 03:26:11	1.231
--- call.c	2000/10/23 06:32:07
*************** standard_conversion (to, from, expr)
*** 685,691 ****
        fcode = TREE_CODE (from);
        conv = build_conv (LVALUE_CONV, from, conv);
      }
!   else if (fromref || (expr && real_lvalue_p (expr)))
      conv = build_conv (RVALUE_CONV, from, conv);
  
     /* Allow conversion between `__complex__' data types  */
--- 685,691 ----
        fcode = TREE_CODE (from);
        conv = build_conv (LVALUE_CONV, from, conv);
      }
!   else if (fromref || (expr && lvalue_p (expr)))
      conv = build_conv (RVALUE_CONV, from, conv);
  
     /* Allow conversion between `__complex__' data types  */
Index: testsuite/g++.old-deja/g++.other/dtor11.C
===================================================================
RCS file: dtor11.C
diff -N dtor11.C
*** /dev/null	Tue May  5 13:32:27 1998
--- dtor11.C	Sun Oct 22 23:32:09 2000
***************
*** 0 ****
--- 1,34 ----
+ // Origin: Mark Mitchell <mark@codesourcery.com>
+ 
+ extern "C" void abort ();
+ 
+ int j;
+ 
+ struct S {
+   S () { ++j; }
+   S (const S&) { ++j; }
+   ~S () {
+     if (--j < 0)
+       abort ();
+    }
+ };
+ 
+ struct T {
+   void g (S) {
+   };
+ };
+ 
+ struct U {
+   int i;
+   S s;
+ };
+ 
+ U u;
+ 
+ U f () { return u; }
+ 
+ int main ()
+ {
+   T t;
+   t.g (f ().s);
+ }


More information about the Gcc-patches mailing list