This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH to suppress bogus -Wunused warning for parameter packs (PR c++/68965)
- From: Marek Polacek <polacek at redhat dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>, Jason Merrill <jason at redhat dot com>
- Date: Wed, 13 Jan 2016 17:50:22 +0100
- Subject: C++ PATCH to suppress bogus -Wunused warning for parameter packs (PR c++/68965)
- Authentication-results: sourceware.org; auth=none
The problem in this PR is that we print bogus "unused parameter" warnings
for parameters of a parameter pack. E.g. for
auto count = [](auto&&... xs)
{
return sizeof...(xs);
};
GCC issues
warning: unused parameter 'xs#0'
warning: unused parameter 'xs#1'
warning: unused parameter 'xs#2'
...
This happens since <https://gcc.gnu.org/ml/gcc-patches/2015-11/msg02433.html>,
because now we aren't calling tsubst_copy that often. But that means that
we're missing the mark_used call in tsubst_copy for those xs# parameters.
So to quash that -Wunused-parameter warning, I decided to set TREE_USED at the
place where we create those #xs parameters.
Bootstrapped/regtested on x86_64-linux, ok for trunk?
2016-01-13 Marek Polacek <polacek@redhat.com>
PR c++/68965
* pt.c (tsubst_decl): Set TREE_USED.
* g++.dg/cpp1y/parameter-pack-1.C: New test.
diff --git gcc/cp/pt.c gcc/cp/pt.c
index edec774..b9d4f59 100644
--- gcc/cp/pt.c
+++ gcc/cp/pt.c
@@ -11924,6 +11924,9 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain)
/* Rename the parameter to include the index. */
DECL_NAME (r)
= make_ith_pack_parameter_name (DECL_NAME (r), i);
+
+ /* Set TREE_USED for the benefit of -Wunused. */
+ TREE_USED (r) = true;
}
else if (!type)
/* We're dealing with a normal parameter. */
diff --git gcc/testsuite/g++.dg/cpp1y/parameter-pack-1.C gcc/testsuite/g++.dg/cpp1y/parameter-pack-1.C
index e69de29..8119b6e 100644
--- gcc/testsuite/g++.dg/cpp1y/parameter-pack-1.C
+++ gcc/testsuite/g++.dg/cpp1y/parameter-pack-1.C
@@ -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,4,5,6,7);
+ count_struct{}(1,2,3,4,5,6,7);
+}
Marek