On 7/11/25 9:09 AM, Jakub Jelinek wrote:
On Thu, Jul 10, 2025 at 04:35:49PM -0400, Jason Merrill wrote:
@@ -211,8 +211,27 @@ mark_use (tree expr, bool rvalue_p, bool
            }
          return expr;
        }
-      gcc_fallthrough();
+      gcc_fallthrough ();
       CASE_CONVERT:
+      if (VOID_TYPE_P (TREE_TYPE (expr)))
+       switch (TREE_CODE (TREE_OPERAND (expr, 0)))
+         {
+         case PREINCREMENT_EXPR:
+         case PREDECREMENT_EXPR:
+         case POSTINCREMENT_EXPR:
+         case POSTDECREMENT_EXPR:

Why is this specific to these codes?  I would think we would want consistent
handling of (void) here and in mark_exp_read.

The second/third levels of the warnings (i.e. the new ones) want
++op0
--op0
op0++
op0--
not to be treated as uses of op0 (but op1 = ++op0 etc. counts as use).
Which is why it checks for these special cases.  The cast to void is there
to just ignore the pre/post inc/decrements alone when their value isn't
used.
The above mark_exp_read changes wouldn't be needed if
     case PREINCREMENT_EXPR:
     case PREDECREMENT_EXPR:
     case POSTINCREMENT_EXPR:
     case POSTDECREMENT_EXPR:
       mark_exp_read (TREE_OPERAND (exp, 0));
       break;
weren't added, but that is needed so that x = ++op0; etc. are treated as
use of op0, while ++op0; on its own is not.

Coming back to this comment, it still seems to me that we can generalize this and ignore anything cast to void here, as in the below; after something has been cast to void, it can no longer be read. I don't get any regressions from this simplification, either.

We might generalize to anything of void type, but I haven't tested that.
commit adcf4220b73a9b7f44a35728f60aa5b351ef51d8
Author: Jason Merrill <ja...@redhat.com>
Date:   Mon Jul 14 18:29:17 2025 -0400

    void

diff --git a/gcc/cp/expr.cc b/gcc/cp/expr.cc
index 8b5a098ecb3..e4a7cfd7bec 100644
--- a/gcc/cp/expr.cc
+++ b/gcc/cp/expr.cc
@@ -214,24 +214,7 @@ mark_use (tree expr, bool rvalue_p, bool read_p,
       gcc_fallthrough ();
     CASE_CONVERT:
       if (VOID_TYPE_P (TREE_TYPE (expr)))
-	switch (TREE_CODE (TREE_OPERAND (expr, 0)))
-	  {
-	  case PREINCREMENT_EXPR:
-	  case PREDECREMENT_EXPR:
-	  case POSTINCREMENT_EXPR:
-	  case POSTDECREMENT_EXPR:
-	    tree op0;
-	    op0 = TREE_OPERAND (TREE_OPERAND (expr, 0), 0);
-	    STRIP_ANY_LOCATION_WRAPPER (op0);
-	    if ((VAR_P (op0) || TREE_CODE (op0) == PARM_DECL)
-		&& !DECL_READ_P (op0)
-		&& (VAR_P (op0) ? warn_unused_but_set_variable
-				: warn_unused_but_set_parameter) > 1)
-	      read_p = false;
-	    break;
-	  default:
-	    break;
-	  }
+	read_p = false;
       recurse_op[0] = true;
       break;
 
@@ -382,16 +365,7 @@ mark_exp_read (tree exp)
       break;
     CASE_CONVERT:
       if (VOID_TYPE_P (TREE_TYPE (exp)))
-	switch (TREE_CODE (TREE_OPERAND (exp, 0)))
-	  {
-	  case PREINCREMENT_EXPR:
-	  case PREDECREMENT_EXPR:
-	  case POSTINCREMENT_EXPR:
-	  case POSTDECREMENT_EXPR:
-	    return;
-	  default:
-	    break;
-	  }
+	return;
       /* FALLTHRU */
     case ARRAY_REF:
     case COMPONENT_REF:

Reply via email to