re PR c++/9165 (false "defined but not used" warnings)
authorMark Mitchell <mark@codesourcery.com>
Tue, 7 Jan 2003 02:38:32 +0000 (02:38 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Tue, 7 Jan 2003 02:38:32 +0000 (02:38 +0000)
PR c++/9165
* decl2.c (build_cleanup): Mark the object as used.

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

From-SVN: r60972

gcc/cp/ChangeLog
gcc/cp/decl2.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/Wunused-3.C [new file with mode: 0644]

index 6e5e223d9050115fd5acda1f5d37413fb8dbe927..2ebbbf72f9c536569b8dffeb377d52babf6d3caa 100644 (file)
@@ -1,5 +1,8 @@
 2003-01-06  Mark Mitchell  <mark@codesourcery.com>
 
+       PR c++/9165
+       * decl2.c (build_cleanup): Mark the object as used.
+
        * pt.c (retrieve_local_specialization): Revert 2003-01-05 change.
        (hash_local_specialization): New function.
        (register_local_specialization): Revert 2003-01-05 change.
index 85b6a2ede38924ffab6abce47881a3f3d3b10314..6363007b4ef466c34213783fb04ae1143c059c02 100644 (file)
@@ -1865,12 +1865,24 @@ import_export_tinfo (tree decl, tree type, bool is_in_library)
   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
index 8b4fce3179c0da8aa8aa65de02fd9d05427aca65..2ae706048873ad06f5bb2b3857d49c1d3688655f 100644 (file)
@@ -1,6 +1,9 @@
 2003-01-06  Mark Mitchell  <mark@codesourcery.com>
 
-       * testsuite/g++.dg/abi/bitfield9.C: New test.
+       PR c++/9165
+       * g++.dg/warn/Wunused-3.C: New test.
+
+       * g++.dg/abi/bitfield9.C: New test.
 
        PR c++/9189
        * g++.dg/parse/defarg3.C: New test.
diff --git a/gcc/testsuite/g++.dg/warn/Wunused-3.C b/gcc/testsuite/g++.dg/warn/Wunused-3.C
new file mode 100644 (file)
index 0000000..3100909
--- /dev/null
@@ -0,0 +1,11 @@
+// { dg-do compile }
+// { dg-options "-Wunused -O" }
+
+void do_cleanups();
+
+class Cleanup {
+public:
+    ~Cleanup() { do_cleanups();}
+};
+
+static Cleanup dummy;