The old build_cleanup called mark_used; the new one that just calls cxx_maybe_build_cleanup didn't any more. So let's add a call in the latter function.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit be2e25f452c30b0a7a00a803422cdbbd80c4e9c3
Author: Jason Merrill <ja...@redhat.com>
Date:   Tue Jan 28 22:30:31 2014 -0500

    	PR c++/59315
    	* decl.c (cxx_maybe_build_cleanup): Call mark_used.

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index e14e401..e57cf07 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -14353,6 +14353,12 @@ cxx_maybe_build_cleanup (tree decl, tsubst_flags_t complain)
      destructor call instead.  */
   if (cleanup != NULL && EXPR_P (cleanup))
     SET_EXPR_LOCATION (cleanup, UNKNOWN_LOCATION);
+
+  if (cleanup)
+    /* Treat all objects with destructors as used; the destructor may do
+       something substantive.  */
+    mark_used (decl);
+
   return cleanup;
 }
 
diff --git a/gcc/testsuite/g++.dg/warn/Wunused-3.C b/gcc/testsuite/g++.dg/warn/Wunused-3.C
index 3100909..2d00dda 100644
--- a/gcc/testsuite/g++.dg/warn/Wunused-3.C
+++ b/gcc/testsuite/g++.dg/warn/Wunused-3.C
@@ -1,5 +1,5 @@
 // { dg-do compile }
-// { dg-options "-Wunused -O" }
+// { dg-options "-Wunused -O -fno-use-cxa-atexit" }
 
 void do_cleanups();
 

Reply via email to