commit 16a145d52dcd75c5da6702ca7024a4570abf6d36
Author: Jason Merrill <jason@redhat.com>
Date: Wed Mar 2 09:40:14 2016 -0500
PR c++/66543 - -Wunused-but-set* false positives
* expr.c (mark_exp_read): Handle NON_DEPENDENT_EXPR.
* pt.c (make_pack_expansion): Call mark_exp_read.
* semantics.c (finish_id_expression): Call mark_type_use in
unevaluated context.
@@ -145,6 +145,7 @@ mark_exp_read (tree exp)
case ADDR_EXPR:
case INDIRECT_REF:
case FLOAT_EXPR:
+ case NON_DEPENDENT_EXPR:
mark_exp_read (TREE_OPERAND (exp, 0));
break;
case COMPOUND_EXPR:
@@ -3696,6 +3696,8 @@ make_pack_expansion (tree arg)
/* Propagate type and const-expression information. */
TREE_TYPE (result) = TREE_TYPE (arg);
TREE_CONSTANT (result) = TREE_CONSTANT (arg);
+ /* Mark this read now, since the expansion might be length 0. */
+ mark_exp_read (arg);
}
else
/* Just use structural equality for these TYPE_PACK_EXPANSIONS;
@@ -3487,6 +3487,12 @@ finish_id_expression (tree id_expression,
if (!scope && decl != error_mark_node && identifier_p (id_expression))
maybe_note_name_used_in_class (id_expression, decl);
+ /* A use in unevaluated operand might not be instantiated appropriately
+ if tsubst_copy builds a dummy parm, or if we never instantiate a
+ generic lambda, so mark it now. */
+ if (processing_template_decl && cp_unevaluated_operand)
+ mark_type_use (decl);
+
/* Disallow uses of local variables from containing functions, except
within lambda-expressions. */
if (outer_automatic_var_p (decl))
new file mode 100644
@@ -0,0 +1,17 @@
+// { dg-do compile { target c++11 } }
+// { dg-options "-Wunused-but-set-parameter" }
+
+template <typename... Ts> void sink(Ts...);
+
+struct A { int i; };
+
+template <int... I>
+void f(A a)
+{
+ return sink((a.i + I)...);
+}
+
+int main()
+{
+ f<>(A());
+}
new file mode 100644
@@ -0,0 +1,9 @@
+// { dg-do compile { target c++14 } }
+// { dg-options "-Wunused-but-set-parameter" }
+
+auto l = [](auto t) -> decltype(true ? t : 0) { return {}; };
+
+int main()
+{
+ l(42);
+}
new file mode 100644
@@ -0,0 +1,10 @@
+// PR c++/66543
+// { dg-do compile { target c++14 } }
+// { dg-options "-Wunused-but-set-variable" }
+
+int main() {
+ auto f = []() { };
+ [=](auto) {
+ using Foo = decltype(f());
+ };
+}
new file mode 100644
@@ -0,0 +1,15 @@
+// { dg-do compile { target c++14 } }
+// { dg-options "-Wunused-but-set-variable" }
+
+template <int... I> struct A { };
+template <int... I>
+auto f()
+{
+ constexpr int ar[sizeof...(I)+1] = {I...};
+ return A<ar[I]...>();
+}
+
+int main()
+{
+ f<>();
+}