On 7/15/25 5:26 AM, Jakub Jelinek wrote:
On Mon, Jul 14, 2025 at 11:58:32PM -0400, Jason Merrill wrote:
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.

We do want to warn for b and not for a e.g. on -Wunused-but-set-variable
void
foo ()
{
   int a, b;
   a = 1;
   b = 2;
   (void) a;
}
Though, from what I can see, we warn correctly even with your patch.

Yes, because the cast itself marks a as read (in convert_to_void); we don't need to also look through the cast later.

I admit I don't know any longer what was the reason for all the special
cases in mark_exp_read and whether over the years some of them might be
unneeded.  We have some test coverage, but only limited (40KB of tests
in c-c++-common & g++.dg), plus sure full bootstrap/regtest does test it
further.

Could it be committed separately though, in case there is some regression
that bisection can find whether it is this simplification or the original
patch?

Given the above that seems rather unlikely, but I suppose it's fine if you want to do it that way. The patch is OK either way.

Jason

Reply via email to