re PR c++/44443 (-Wunused-but-set-variable problem with unused attribute on type)
authorJakub Jelinek <jakub@redhat.com>
Mon, 7 Jun 2010 17:49:06 +0000 (19:49 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 7 Jun 2010 17:49:06 +0000 (19:49 +0200)
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
gcc/cp/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/Wunused-var-11.c [new file with mode: 0644]

index 6e4c35eb18a2aa82bd986e5a3552f6781580d981..622a79349b0fd120dc864379317d2109ba66d5da 100644 (file)
@@ -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
index c9f864a6eaf3dd092816dc6d4a59697535789e2b..171e160b2af54c2039cade27e153ec2744c6834b 100644 (file)
@@ -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);
index 392e0bf2f3890951bc8737e885d5c55ff9c35747..a2ac15621ce9355dab4b21f97e3d046c3916a789 100644 (file)
@@ -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 (file)
index 0000000..a59ef81
--- /dev/null
@@ -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;
+}