c++/9165: [3.3/3.4 regression] false "defined but not used" warnings

Mark Mitchell mark@codesourcery.com
Mon Jan 13 05:17:00 GMT 2003



--On Monday, January 06, 2003 03:01:36 PM -0800 Joe Buck 
<jbuck@synopsys.com> wrote:

> On Mon, Jan 06, 2003 at 02:43:44PM -0800, Janis Johnson wrote:
>> The regression showed up with this patch:
>>

> Thanks, Janis.  Mark, could you have a look at this when you get a chance?
> It seems that the error arises because, after inlining, nothing touches
> the Cleanup object (since the body of the destructor calls a function
> that does not take the Cleanup object as an argument).

Fixed with this patch.

Tested on i686-pc-linux-gnu, applied on the mainline and on the 3.3
branch.

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

2003-01-06  Mark Mitchell  <mark@codesourcery.com>

	PR c++/9165
	* decl2.c (build_cleanup): Mark the object as used.

2003-01-06  Mark Mitchell  <mark@codesourcery.com>

	PR c++/9165
	* g++.dg/warn/Wunused-3.C: New test.

Index: testsuite/g++.dg/warn/Wunused-3.C
===================================================================
RCS file: testsuite/g++.dg/warn/Wunused-3.C
diff -N testsuite/g++.dg/warn/Wunused-3.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/warn/Wunused-3.C	7 Jan 2003 02:31:09 -0000
***************
*** 0 ****
--- 1,11 ----
+ // { dg-do compile }
+ // { dg-options "-Wunused -O" }
+
+ void do_cleanups();
+
+ class Cleanup {
+ public:
+     ~Cleanup() { do_cleanups();}
+ };
+
+ static Cleanup dummy;
Index: cp/decl2.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl2.c,v
retrieving revision 1.591
diff -c -5 -p -r1.591 decl2.c
*** cp/decl2.c	7 Jan 2003 01:34:37 -0000	1.591
--- cp/decl2.c	7 Jan 2003 02:31:14 -0000
*************** import_export_tinfo (tree decl, tree typ
*** 1863,1877 ****
--- 1863,1889 ----
      DECL_COMDAT (decl) = 0;

    DECL_INTERFACE_KNOWN (decl) = 1;
  }

+ /* Return an expression that performs the destruction of DECL, which
+    must be a VAR_DECL whose type has a non-trivial destructor, or is
+    an array whose (innermost) elements have a non-trivial destructor.  */
+
  tree
  build_cleanup (tree decl)
  {
    tree temp;
    tree type = TREE_TYPE (decl);
+
+   /* This function should only be called for declarations that really
+      require cleanups.  */
+   my_friendly_assert (!TYPE_HAS_TRIVIAL_DESTRUCTOR (type), 20030106);
+
+   /* Treat all objects with destructors as used; the destructor may do
+      something substantive.  */
+   mark_used (decl);

    if (TREE_CODE (type) == ARRAY_TYPE)
      temp = decl;
    else
      {



More information about the Gcc-bugs mailing list