lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

>> -Wunused-value
> Itâ??s hard to imagine how this warning could be considered â??low-to-negati$

Because a lot of things produce values which are then ignored.  (Most
statements, actually, I suspect.  Any expression statement with a type
other than void; my guess is that that's a majority of statements.)

It's described as "Warn whenever a statement computes a result that is
explicitly not used".  That includes almost all expression statements.

> It always means that there is some redundancy in your code,

Maybe.  But I'm not going to cast all expression statements to void
just to pacify a warning option, even if there is theoretical
redundancy involved.

Here's an actual piece of code from an actual program I wrote.  All
five expression statements here have assignments as their top-level
operators and would need casts to void based on that description.

 for (i=rows-1;i>=0;i--)
  { coeffs[i] = p;
    p += rows;
 for (i=rows-1;i>=0;i--)
  { k = 1;
    for (j=0;j<rows;j++)
     { coeffs[i][j] = k;
       k *= i + x0;

Because of the precedence rules, these would actually need parens as
well, as in (void)(k = 1);.  What redundancies do these indicate?  What
probable mistakes do they indicate?

> Perhaps you saved a result into a variable but later â??retrievedâ?? it for $

How would that trip this warning?  Saving the value into the variable
would, unless cast to void or used some other way, produce a value
which would then be ignored.

> (Unused values that arenâ??t needed should be removed.  They are just a need$

Unfortunately, almost all expression statement return values which
aren't used.  (I'm not sure what it means for the value to be
"explicitly not used"; I don't see how lack-of-use can be explicit.
Maybe I'm missing something.)  The only exceptions are ones which
"return" void; the only expressions with values of type void are those
which are cast that way and function calls which are declared to return
void.  Those exist, but they are rare as compared to, say, assignment

That's why it has low-to-negative value in my opinion.

If the description had been "without side effects" or some such, that
would have been more defensible - but even then a lot of calls, like
printf, would need casts to void.  Maybe description in the manpage I
have is incorrect.

/~\ The ASCII				  Mouse
\ / Ribbon Campaign
 X  Against HTML
/ \ Email!	     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B