tree, tree);
extern void warn_logical_not_parentheses (location_t, enum tree_code, tree,
tree);
-extern bool warn_if_unused_value (const_tree, location_t);
+extern bool warn_if_unused_value (const_tree, location_t, bool = false);
extern bool strict_aliasing_warning (location_t, tree, tree);
extern void sizeof_pointer_memaccess_warning (location_t *, tree,
vec<tree, va_gc> *, tree *,
(potential) location of the expression. */
bool
-warn_if_unused_value (const_tree exp, location_t locus)
+warn_if_unused_value (const_tree exp, location_t locus, bool quiet)
{
restart:
if (TREE_USED (exp) || TREE_NO_WARNING (exp))
goto restart;
case COMPOUND_EXPR:
- if (warn_if_unused_value (TREE_OPERAND (exp, 0), locus))
+ if (warn_if_unused_value (TREE_OPERAND (exp, 0), locus, quiet))
return true;
/* Let people do `(foo (), 0)' without a warning. */
if (TREE_CONSTANT (TREE_OPERAND (exp, 1)))
return false;
goto warn;
+ case COMPLEX_EXPR:
+ /* Warn only if both operands are unused. */
+ if (warn_if_unused_value (TREE_OPERAND (exp, 0), locus, true)
+ && warn_if_unused_value (TREE_OPERAND (exp, 1), locus, true))
+ goto warn;
+ return false;
+
case INDIRECT_REF:
/* Don't warn about automatic dereferencing of references, since
the user cannot control it. */
return false;
warn:
+ if (quiet)
+ return true;
return warning_at (locus, OPT_Wunused_value, "value computed is not used");
}
}
&& warn_unused_value
&& !TREE_NO_WARNING (expr)
&& !processing_template_decl
- && !cp_unevaluated_operand)
+ && !cp_unevaluated_operand
+ && (complain & tf_warning))
{
/* The middle end does not warn about expressions that have
been explicitly cast to void, so we must do so here. */
- if (!TREE_SIDE_EFFECTS (expr)) {
- if (complain & tf_warning)
+ if (!TREE_SIDE_EFFECTS (expr))
+ {
switch (implicit)
{
case ICV_SECOND_OF_COND:
default:
gcc_unreachable ();
}
- }
+ }
else
{
- tree e;
- enum tree_code code;
- enum tree_code_class tclass;
-
- e = expr;
+ tree e = expr;
/* We might like to warn about (say) "(int) f()", as the
cast has no effect, but the compiler itself will
generate implicit conversions under some
while (TREE_CODE (e) == NOP_EXPR)
e = TREE_OPERAND (e, 0);
- code = TREE_CODE (e);
- tclass = TREE_CODE_CLASS (code);
- if ((tclass == tcc_comparison
- || tclass == tcc_unary
- || (tclass == tcc_binary
- && !(code == MODIFY_EXPR
- || code == INIT_EXPR
- || code == PREDECREMENT_EXPR
- || code == PREINCREMENT_EXPR
- || code == POSTDECREMENT_EXPR
- || code == POSTINCREMENT_EXPR))
- || code == VEC_PERM_EXPR
- || code == VEC_COND_EXPR)
- && (complain & tf_warning))
- warning_at (loc, OPT_Wunused_value, "value computed is not used");
+ enum tree_code code = TREE_CODE (e);
+ enum tree_code_class tclass = TREE_CODE_CLASS (code);
+ if (tclass == tcc_comparison
+ || tclass == tcc_unary
+ || tclass == tcc_binary
+ || code == VEC_PERM_EXPR
+ || code == VEC_COND_EXPR)
+ warn_if_unused_value (e, loc);
}
}
expr = build1 (CONVERT_EXPR, void_type_node, expr);
--- /dev/null
+/* PR c/97748 */
+/* { dg-do compile } */
+/* { dg-options "-Wunused-value" } */
+
+double _Complex f ();
+double _Complex *p;
+
+double _Complex
+foo (double _Complex x)
+{
+ ++x; /* { dg-bogus "value computed is not used" } */
+ --x; /* { dg-bogus "value computed is not used" } */
+ x += 1; /* { dg-bogus "value computed is not used" } */
+ x += 1.0iF; /* { dg-bogus "value computed is not used" } */
+ x++; /* { dg-bogus "value computed is not used" } */
+ x--; /* { dg-bogus "value computed is not used" } */
+ x + 1; /* { dg-warning "value computed is not used" } */
+ (void) (x + 1); /* { dg-bogus "value computed is not used" } */
+ 1 + f (); /* { dg-warning "value computed is not used" } */
+ f () + f (); /* { dg-warning "value computed is not used" } */
+ f () + f (), f (); /* { dg-warning "value computed is not used" } */
+ f ();
+ (void) f ();
+ *p++; /* { dg-warning "value computed is not used" } */
+ ++*p; /* { dg-bogus "value computed is not used" } */
+ (*p ? f () : 0);
+ ({ f (); });
+ ({ f () + 1; });
+ ({ f (); 0; });
+ ({ f () + 1; 0; }); /* { dg-warning "value computed is not used" } */
+ 1 + ({ f (); }); /* { dg-warning "value computed is not used" } */
+ return x;
+}