Commit 76f39440 by Jason Merrill Committed by Jason Merrill

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.

From-SVN: r235221
parent 90eeab20
2016-04-19 Jason Merrill <jason@redhat.com> 2016-04-19 Jason Merrill <jason@redhat.com>
PR c++/66543
* 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.
DR 2137 DR 2137
* call.c (implicit_conversion): If we choose a copy constructor * call.c (implicit_conversion): If we choose a copy constructor
for list-initialization from the same type, the conversion is an for list-initialization from the same type, the conversion is an
......
...@@ -145,6 +145,7 @@ mark_exp_read (tree exp) ...@@ -145,6 +145,7 @@ mark_exp_read (tree exp)
case ADDR_EXPR: case ADDR_EXPR:
case INDIRECT_REF: case INDIRECT_REF:
case FLOAT_EXPR: case FLOAT_EXPR:
case NON_DEPENDENT_EXPR:
mark_exp_read (TREE_OPERAND (exp, 0)); mark_exp_read (TREE_OPERAND (exp, 0));
break; break;
case COMPOUND_EXPR: case COMPOUND_EXPR:
......
...@@ -3696,6 +3696,8 @@ make_pack_expansion (tree arg) ...@@ -3696,6 +3696,8 @@ make_pack_expansion (tree arg)
/* Propagate type and const-expression information. */ /* Propagate type and const-expression information. */
TREE_TYPE (result) = TREE_TYPE (arg); TREE_TYPE (result) = TREE_TYPE (arg);
TREE_CONSTANT (result) = TREE_CONSTANT (arg); TREE_CONSTANT (result) = TREE_CONSTANT (arg);
/* Mark this read now, since the expansion might be length 0. */
mark_exp_read (arg);
} }
else else
/* Just use structural equality for these TYPE_PACK_EXPANSIONS; /* Just use structural equality for these TYPE_PACK_EXPANSIONS;
......
...@@ -3487,6 +3487,12 @@ finish_id_expression (tree id_expression, ...@@ -3487,6 +3487,12 @@ finish_id_expression (tree id_expression,
if (!scope && decl != error_mark_node && identifier_p (id_expression)) if (!scope && decl != error_mark_node && identifier_p (id_expression))
maybe_note_name_used_in_class (id_expression, decl); 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 /* Disallow uses of local variables from containing functions, except
within lambda-expressions. */ within lambda-expressions. */
if (outer_automatic_var_p (decl)) if (outer_automatic_var_p (decl))
......
// { 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());
}
// { 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);
}
// PR c++/66543
// { dg-do compile { target c++14 } }
// { dg-options "-Wunused-but-set-variable" }
int main() {
auto f = []() { };
[=](auto) {
using Foo = decltype(f());
};
}
// { 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<>();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment