This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH] Fix -Wunused-but-set-* for variables with TREE_USED type (PR c++/44443)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Jason Merrill <jason at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Mon, 7 Jun 2010 17:34:57 +0200
- Subject: [C++ PATCH] Fix -Wunused-but-set-* for variables with TREE_USED type (PR c++/44443)
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
This is something the C FE already handles fine. If a type is TREE_USED,
we need to mark decl as DECL_READ_P, because in that case
handle_unused_attribute doesn't set DECL_READ_P itself.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
2010-06-07 Jakub Jelinek <jakub@redhat.com>
PR c++/44443
* decl.c (initialize_local_var): If TREE_USED is set on the type,
set also DECL_READ_P on the decl.
* c-c++-common/Wunused-var-11.c: New test.
--- gcc/cp/decl.c.jj 2010-06-07 11:25:02.000000000 +0200
+++ gcc/cp/decl.c 2010-06-07 13:03:02.000000000 +0200
@@ -5508,6 +5508,8 @@ initialize_local_var (tree decl, tree in
/* Compute and store the initial value. */
already_used = TREE_USED (decl) || TREE_USED (type);
+ if (TREE_USED (type))
+ DECL_READ_P (decl) = 1;
/* Generate a cleanup, if necessary. */
cleanup = cxx_maybe_build_cleanup (decl);
--- gcc/testsuite/c-c++-common/Wunused-var-11.c.jj 2010-06-07 14:44:58.000000000 +0200
+++ gcc/testsuite/c-c++-common/Wunused-var-11.c 2010-06-07 14:45:09.000000000 +0200
@@ -0,0 +1,12 @@
+/* PR c++/44443 */
+/* { dg-options "-Wunused" } */
+/* { dg-do compile } */
+
+int i;
+
+void
+f1 ()
+{
+ const int * __attribute__((unused)) a = &i;
+ const int *b __attribute__((unused)) = &i;
+}
Jakub