From 026698d28e6eac591edfc8b1fd397e73b0503c56 Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>
Date: Mon, 7 Jun 2010 19:49:06 +0200
Subject: [PATCH] re PR c++/44443 (-Wunused-but-set-variable problem with
 unused attribute on type)

	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.

From-SVN: r160387
---
 gcc/cp/ChangeLog                            |  6 ++++++
 gcc/cp/decl.c                               |  2 ++
 gcc/testsuite/ChangeLog                     |  5 +++++
 gcc/testsuite/c-c++-common/Wunused-var-11.c | 12 ++++++++++++
 4 files changed, 25 insertions(+)
 create mode 100644 gcc/testsuite/c-c++-common/Wunused-var-11.c

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 6e4c35eb18a2..622a79349b0f 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+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.
+
 2010-05-25  Dodji Seketeli  <dodji@redhat.com>
 
 	PR c++/44188
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index c9f864a6eaf3..171e160b2af5 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -5508,6 +5508,8 @@ initialize_local_var (tree decl, tree init)
 
   /* 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);
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 392e0bf2f389..a2ac15621ce9 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2010-06-07  Jakub Jelinek  <jakub@redhat.com>
+
+	PR c++/44443
+	* c-c++-common/Wunused-var-11.c: New test.
+
 2010-06-07  Jan Hubicka  <jh@suse.cz>
 
 	* gcc.dg/ipa/pure-const-1.c: New testcase.
diff --git a/gcc/testsuite/c-c++-common/Wunused-var-11.c b/gcc/testsuite/c-c++-common/Wunused-var-11.c
new file mode 100644
index 000000000000..a59ef8149386
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/Wunused-var-11.c
@@ -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;
+}
-- 
GitLab