re PR c++/71442 (r232569 breaks -Wunused-*)
authorJakub Jelinek <jakub@redhat.com>
Wed, 8 Jun 2016 17:57:30 +0000 (19:57 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 8 Jun 2016 17:57:30 +0000 (19:57 +0200)
PR c++/71442
* pt.c (tsubst_copy): Only set TREE_USED on DECLs.

* g++.dg/cpp0x/Wunused-variable-1.C: New test.

From-SVN: r237232

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/Wunused-variable-1.C [new file with mode: 0644]

index 86dddd210d7074c16026ae34414d932bf3ce58a9..1627fd214c0d7e90ea2abc2d2118890ce669909a 100644 (file)
@@ -1,3 +1,8 @@
+2016-06-08  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/71442
+       * pt.c (tsubst_copy): Only set TREE_USED on DECLs.
+
 2016-06-06  Jakub Jelinek  <jakub@redhat.com>
            Patrick Palka  <ppalka@gcc.gnu.org>
 
index 64fef68c9e389ebcd67e2ab811ff592e60b35d52..4ccdd45b73b971eb97a7a07a2ac94f07abb54d11 100644 (file)
@@ -14160,7 +14160,8 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl)
              len = TREE_VEC_LENGTH (expanded);
              /* Set TREE_USED for the benefit of -Wunused.  */
              for (int i = 0; i < len; i++)
-               TREE_USED (TREE_VEC_ELT (expanded, i)) = true;
+               if (DECL_P (TREE_VEC_ELT (expanded, i)))
+                 TREE_USED (TREE_VEC_ELT (expanded, i)) = true;
            }
 
          if (expanded == error_mark_node)
index 93062fd78ef0c5a39b51b64421069bdae9e06012..2f3e4e16766f3c56d6efd10b0060f2c64b3c8a3b 100644 (file)
@@ -1,3 +1,8 @@
+2016-06-08  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/71442
+       * g++.dg/cpp0x/Wunused-variable-1.C: New test.
+
 2016-06-08  Alan Lawrence  <alan.lawrence@arm.com>
 
        * gcc.target/aarch64/aapcs64/aapcs64.exp: Also execute rec_*.c
diff --git a/gcc/testsuite/g++.dg/cpp0x/Wunused-variable-1.C b/gcc/testsuite/g++.dg/cpp0x/Wunused-variable-1.C
new file mode 100644 (file)
index 0000000..39592b2
--- /dev/null
@@ -0,0 +1,37 @@
+// PR c++/71442
+// { dg-do compile { target c++11 } }
+// { dg-options "-Wunused-variable" }
+
+struct C
+{
+  template<typename... Ts>
+  int operator()(Ts &&...)
+  {
+    return sizeof...(Ts);
+  }
+};
+
+int
+foo ()
+{
+  C {} (1, 1L, 1LL, 1.0);
+}
+
+template<int N>
+void
+bar ()
+{
+  char a;              // { dg-warning "unused variable" }
+  short b;             // { dg-warning "unused variable" }
+  int c;               // { dg-warning "unused variable" }
+  long d;              // { dg-warning "unused variable" }
+  long long e;         // { dg-warning "unused variable" }
+  float f;             // { dg-warning "unused variable" }
+  double g;            // { dg-warning "unused variable" }
+}
+
+void
+baz ()
+{
+  bar <0> ();
+}