re PR c++/68965 (`-Wunused-parameter` is reported in variadic lambda or function...
authorMarek Polacek <polacek@redhat.com>
Tue, 19 Jan 2016 14:37:49 +0000 (14:37 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Tue, 19 Jan 2016 14:37:49 +0000 (14:37 +0000)
PR c++/68965
* pt.c (tsubst_copy): Mark elements in expanded vector as used.

* g++.dg/cpp1y/parameter-pack-1.C: New test.
* g++.dg/cpp1y/parameter-pack-2.C: New test.

From-SVN: r232569

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp1y/parameter-pack-1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp1y/parameter-pack-2.C [new file with mode: 0644]

index f9fce9d..ac2bbae 100644 (file)
@@ -6,6 +6,9 @@
        * cp-tree.h (clear_cv_cache, clear_fold_cache): Declare.
        * decl.c (finish_enum_value_list): Call them.
 
+       PR c++/68965
+       * pt.c (tsubst_copy): Mark elements in expanded vector as used.
+
 2016-01-18  Patrick Palka  <ppalka@gcc.gnu.org>
 
        PR c++/11858
index 866b4b1..6062ebe 100644 (file)
@@ -14010,7 +14010,12 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl)
          --c_inhibit_evaluation_warnings;
 
          if (TREE_CODE (expanded) == TREE_VEC)
-           len = TREE_VEC_LENGTH (expanded);
+           {
+             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 (expanded == error_mark_node)
            return error_mark_node;
index f360afd..a75c88e 100644 (file)
@@ -1,3 +1,9 @@
+2016-01-19  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/68965
+       * g++.dg/cpp1y/parameter-pack-1.C: New test.
+       * g++.dg/cpp1y/parameter-pack-2.C: New test.
+
 2016-01-19  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
 
        PR target/69135
diff --git a/gcc/testsuite/g++.dg/cpp1y/parameter-pack-1.C b/gcc/testsuite/g++.dg/cpp1y/parameter-pack-1.C
new file mode 100644 (file)
index 0000000..27a6bf9
--- /dev/null
@@ -0,0 +1,23 @@
+// PR c++/68965
+// { dg-do compile { target c++14 } }
+// { dg-options "-Wall -Wextra" }
+
+auto count = [](auto&&... xs)
+{
+    return sizeof...(xs);
+};
+
+struct count_struct
+{
+    template<typename... Ts>
+    auto operator()(Ts&&... xs)
+    {
+        return sizeof...(xs);
+    }
+};
+
+int main()
+{
+    count(1,2,3);
+    count_struct{}(1,2,3);
+}
diff --git a/gcc/testsuite/g++.dg/cpp1y/parameter-pack-2.C b/gcc/testsuite/g++.dg/cpp1y/parameter-pack-2.C
new file mode 100644 (file)
index 0000000..9520875
--- /dev/null
@@ -0,0 +1,21 @@
+// PR c++/68965
+// { dg-do compile { target c++14 } }
+// { dg-options "-Wall -Wextra" }
+
+auto count = [](auto&&... xs) // { dg-warning "unused parameter" }
+{
+};
+
+struct count_struct
+{
+    template<typename... Ts>
+    auto operator()(Ts&&... xs) // { dg-warning "unused parameter" }
+    {
+    }
+};
+
+int main()
+{
+    count(1,2,3);
+    count_struct{}(1,2,3);
+}