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: Fix PR 8724


PR 8724 is a regression whereby we fail to reject an illegal use of a
destructor.

This is already fixed on the mainline (due to the new parser), but
here's the fix for the 3.3 branch.

Tested on i686-pc-linux-gnu, applied on the 3.3 branch.  I'll apply
the test case to the mainline as well.

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

2003-02-21  Mark Mitchell  <mark at codesourcery dot com>

	PR c++/8724
	* call.c (build_method_call): Make sure that the type destroyed in
	an explicit destructor call is complete.

2003-02-21  Mark Mitchell  <mark at codesourcery dot com>

	PR c++/8724
	* g++.dg/expr/dtor1.C: New test.

Index: testsuite/g++.dg/expr/dtor1.C
===================================================================
RCS file: testsuite/g++.dg/expr/dtor1.C
diff -N testsuite/g++.dg/expr/dtor1.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/expr/dtor1.C	21 Feb 2003 17:56:46 -0000
***************
*** 0 ****
--- 1,7 ----
+ class Foo;
+ 
+ void
+ bar(void* p)
+ {
+   static_cast<Foo*>(p)->~Foo(); // { dg-error "" }
+ }
Index: cp/call.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/call.c,v
retrieving revision 1.341.2.4
diff -c -5 -p -r1.341.2.4 call.c
*** cp/call.c	17 Jan 2003 22:51:46 -0000	1.341.2.4
--- cp/call.c	21 Feb 2003 17:56:49 -0000
*************** build_method_call (instance, name, parms
*** 517,527 ****
        if (! check_dtor_name (object_type, name))
  	error
  	  ("destructor name `~%T' does not match type `%T' of expression",
  	   TREE_OPERAND (name, 0), object_type);
  
!       if (! TYPE_HAS_DESTRUCTOR (complete_type (object_type)))
  	return cp_convert (void_type_node, instance);
        instance = default_conversion (instance);
        instance_ptr = build_unary_op (ADDR_EXPR, instance, 0);
        return build_delete (build_pointer_type (object_type),
  			   instance_ptr, sfk_complete_destructor,
--- 517,532 ----
        if (! check_dtor_name (object_type, name))
  	error
  	  ("destructor name `~%T' does not match type `%T' of expression",
  	   TREE_OPERAND (name, 0), object_type);
  
!       /* The destructor type must be complete.  */
!       object_type = complete_type_or_else (object_type, NULL_TREE);
!       if (!object_type || object_type == error_mark_node)
! 	return error_mark_node;
! 
!       if (! TYPE_HAS_DESTRUCTOR (object_type))
  	return cp_convert (void_type_node, instance);
        instance = default_conversion (instance);
        instance_ptr = build_unary_op (ADDR_EXPR, instance, 0);
        return build_delete (build_pointer_type (object_type),
  			   instance_ptr, sfk_complete_destructor,


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