Commit 03943bbd by Jason Merrill Committed by Jason Merrill

PR c++/82728 - wrong -Wunused-but-set-variable

	PR c++/82799
	PR c++/83690
	* call.c (perform_implicit_conversion_flags): Call mark_rvalue_use.
	* decl.c (case_conversion): Likewise.
	* semantics.c (finish_static_assert): Call
	perform_implicit_conversion_flags.

From-SVN: r256550
parent c2893c6e
2018-01-11 Jason Merrill <jason@redhat.com>
PR c++/82728 - wrong -Wunused-but-set-variable
PR c++/82799
PR c++/83690
* call.c (perform_implicit_conversion_flags): Call mark_rvalue_use.
* decl.c (case_conversion): Likewise.
* semantics.c (finish_static_assert): Call
perform_implicit_conversion_flags.
2018-01-11 Nathan Sidwell <nathan@acm.org> 2018-01-11 Nathan Sidwell <nathan@acm.org>
* method.c (enum mangling_flags): Delete long-dead enum. * method.c (enum mangling_flags): Delete long-dead enum.
......
...@@ -10514,6 +10514,11 @@ perform_implicit_conversion_flags (tree type, tree expr, ...@@ -10514,6 +10514,11 @@ perform_implicit_conversion_flags (tree type, tree expr,
void *p; void *p;
location_t loc = EXPR_LOC_OR_LOC (expr, input_location); location_t loc = EXPR_LOC_OR_LOC (expr, input_location);
if (TREE_CODE (type) == REFERENCE_TYPE)
expr = mark_lvalue_use (expr);
else
expr = mark_rvalue_use (expr);
if (error_operand_p (expr)) if (error_operand_p (expr))
return error_mark_node; return error_mark_node;
......
...@@ -3541,6 +3541,8 @@ case_conversion (tree type, tree value) ...@@ -3541,6 +3541,8 @@ case_conversion (tree type, tree value)
if (value == NULL_TREE) if (value == NULL_TREE)
return value; return value;
value = mark_rvalue_use (value);
if (cxx_dialect >= cxx11 if (cxx_dialect >= cxx11
&& (SCOPED_ENUM_P (type) && (SCOPED_ENUM_P (type)
|| !INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (value)))) || !INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (value))))
......
...@@ -8608,6 +8608,8 @@ void ...@@ -8608,6 +8608,8 @@ void
finish_static_assert (tree condition, tree message, location_t location, finish_static_assert (tree condition, tree message, location_t location,
bool member_p) bool member_p)
{ {
tsubst_flags_t complain = tf_warning_or_error;
if (message == NULL_TREE if (message == NULL_TREE
|| message == error_mark_node || message == error_mark_node
|| condition == NULL_TREE || condition == NULL_TREE
...@@ -8640,9 +8642,9 @@ finish_static_assert (tree condition, tree message, location_t location, ...@@ -8640,9 +8642,9 @@ finish_static_assert (tree condition, tree message, location_t location,
} }
/* Fold the expression and convert it to a boolean value. */ /* Fold the expression and convert it to a boolean value. */
condition = instantiate_non_dependent_expr (condition); condition = perform_implicit_conversion_flags (boolean_type_node, condition,
condition = cp_convert (boolean_type_node, condition, tf_warning_or_error); complain, LOOKUP_NORMAL);
condition = maybe_constant_value (condition); condition = fold_non_dependent_expr (condition);
if (TREE_CODE (condition) == INTEGER_CST && !integer_zerop (condition)) if (TREE_CODE (condition) == INTEGER_CST && !integer_zerop (condition))
/* Do nothing; the condition is satisfied. */ /* Do nothing; the condition is satisfied. */
......
// PR c++/82728
// { dg-do compile { target c++11 } }
void
foo ()
{
const int i = 1;
[=]()
{
switch (0)
{
case i:
break;
}
static_assert (i, "i");
};
}
// PR c++/82728
// { dg-do compile }
// { dg-options "-Wunused-but-set-variable" }
void
foo ()
{
const int i = 1; // { dg-bogus "set but not used" }
switch (0)
{
case i:
break;
}
}
// PR c++/82799
// { dg-do compile }
// { dg-options "-Wunused-but-set-variable" }
enum E { b };
struct C {
template <E>
int foo ()
{
const bool i = 0; // { dg-bogus "set but not used" }
const int r = i ? 7 : 9;
return r;
}
void bar () { foo <b> (); }
};
// PR c++/83690
// { dg-do compile { target c++11 } }
// { dg-options "-Wunused-but-set-variable" }
void
foo ()
{
constexpr bool foo = true; // { dg-bogus "set but not used" }
static_assert (foo, "foo");
}
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