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
This commit is contained in:
Jason Merrill 2016-04-19 15:30:22 -04:00 committed by Jason Merrill
parent 90eeab20f7
commit 76f3944041
8 changed files with 66 additions and 0 deletions

View file

@ -1,5 +1,11 @@
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
* call.c (implicit_conversion): If we choose a copy constructor
for list-initialization from the same type, the conversion is an

View file

@ -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:

View file

@ -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;

View file

@ -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))

View file

@ -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());
}

View file

@ -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);
}

View file

@ -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());
};
}

View file

@ -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<>();
}