Discussion:
how to deal with variable set but not used warnings?
(too old to reply)
Rick Macklem
2018-06-03 21:28:47 UTC
Permalink
mmacy has sent me a bunch of warnings of the "variable set but not used" kind
generated by gcc8.

When I've looked at the code, these are for RPC arguments I parse but do not
use at this time.
I'd like to leave the code in place, since these arguments may be needed in the
future and it is hard to figure out how to get them years from now, when they
might be needed.
I can think of 3 ways to handle this:
1 - Get rid of the code. (As above, I'd rather not do this.)
2 - Wrap the code with "#if 0"/"#endif" or similar. I'll admit that I find this rather
ugly and tends to make the code harder to follow.
3 - Leave the code and add a comment w.r.t. why the variables are set but not used.

So, what do others think is the preferable alternative?
(Or maybe you have a #4 that seems better than any of these.)

Thanks for your comments, rick
Warner Losh
2018-06-03 21:33:02 UTC
Permalink
On Sun, Jun 3, 2018 at 3:28 PM, Rick Macklem <***@uoguelph.ca> wrote:

> mmacy has sent me a bunch of warnings of the "variable set but not used"
> kind
> generated by gcc8.
>
> When I've looked at the code, these are for RPC arguments I parse but do
> not
> use at this time.
> I'd like to leave the code in place, since these arguments may be needed
> in the
> future and it is hard to figure out how to get them years from now, when
> they
> might be needed.
> I can think of 3 ways to handle this:
> 1 - Get rid of the code. (As above, I'd rather not do this.)
> 2 - Wrap the code with "#if 0"/"#endif" or similar. I'll admit that I find
> this rather
> ugly and tends to make the code harder to follow.
> 3 - Leave the code and add a comment w.r.t. why the variables are set but
> not used.
>
> So, what do others think is the preferable alternative?
> (Or maybe you have a #4 that seems better than any of these.)
>

4. Disable the stupid warning in the Makefile / build system. If you don't
care, and there's a good reason for what you are doing (sounds like there
is), better to just disable the warning as so much useless noise.

Warner
Theron
2018-06-03 21:40:15 UTC
Permalink
On 06/03/18 17:33, Warner Losh wrote:
> On Sun, Jun 3, 2018 at 3:28 PM, Rick Macklem <***@uoguelph.ca> wrote:
>
>> mmacy has sent me a bunch of warnings of the "variable set but not used"
>> kind
>> generated by gcc8.
>>
>> When I've looked at the code, these are for RPC arguments I parse but do
>> not
>> use at this time.
>> I'd like to leave the code in place, since these arguments may be needed
>> in the
>> future and it is hard to figure out how to get them years from now, when
>> they
>> might be needed.
>> I can think of 3 ways to handle this:
>> 1 - Get rid of the code. (As above, I'd rather not do this.)
>> 2 - Wrap the code with "#if 0"/"#endif" or similar. I'll admit that I find
>> this rather
>> ugly and tends to make the code harder to follow.
>> 3 - Leave the code and add a comment w.r.t. why the variables are set but
>> not used.
>>
>> So, what do others think is the preferable alternative?
>> (Or maybe you have a #4 that seems better than any of these.)
>>
> 4. Disable the stupid warning in the Makefile / build system. If you don't
> care, and there's a good reason for what you are doing (sounds like there
> is), better to just disable the warning as so much useless noise.
>
> Warner
> _______________________________________________
> freebsd-***@freebsd.org mailing list
> https://lists.freebsd.org/mailman/listinfo/freebsd-current
> To unsubscribe, send any mail to "freebsd-current-***@freebsd.org"
Or possibly, alongside a comment as in (3), use one of these:
5 - Disable warning pragma -
http://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html
6 - Use __attribute__((unused)) -
https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#Common-Variable-Attributes
Matthew Macy
2018-06-03 21:43:47 UTC
Permalink
On Sun, Jun 3, 2018 at 2:40 PM, Theron <***@gmail.com> wrote:
>> 4. Disable the stupid warning in the Makefile / build system. If you don't
>> care, and there's a good reason for what you are doing (sounds like there
>> is), better to just disable the warning as so much useless noise.
>>
>> Warner
>> _______________________________________________
>> freebsd-***@freebsd.org mailing list
>> https://lists.freebsd.org/mailman/listinfo/freebsd-current
>> To unsubscribe, send any mail to "freebsd-current-***@freebsd.org"
>
> Or possibly, alongside a comment as in (3), use one of these:
> 5 - Disable warning pragma -
> http://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html
> 6 - Use __attribute__((unused)) -
> https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#Common-Variable-Attributes


There is already an __unused alias for #6. It's what I've used to
annotate variables that are only used by INVARIANTS builds. It
legitimately finds a bunch of dead code. However, 90+% of the
instances of the warning are not interesting.
-M
Rick Macklem
2018-06-04 11:48:15 UTC
Permalink
Matthew Macy wrote:
>On Sun, Jun 3, 2018 at 2:40 PM, Theron <***@gmail.com> wrote:
>>> 4. Disable the stupid warning in the Makefile / build system. If you don't
>>> care, and there's a good reason for what you are doing (sounds like there
>>> is), better to just disable the warning as so much useless noise.
>>>
>>> Warner
>>> _______________________________________________
>>> freebsd-***@freebsd.org mailing list
>>> https://lists.freebsd.org/mailman/listinfo/freebsd-current
>>> To unsubscribe, send any mail to "freebsd-current-***@freebsd.org"
>>
>> Or possibly, alongside a comment as in (3), use one of these:
>> 5 - Disable warning pragma -
>> http://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html
>> 6 - Use __attribute__((unused)) -
> https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#Common-Variable-Attributes
>
>
>There is already an __unused alias for #6. It's what I've used to
>annotate variables that are only used by INVARIANTS builds. It
>legitimately finds a bunch of dead code. However, 90+% of the
>instances of the warning are not interesting.
Ok. I didn't realize that __unused would work for this case of "set but not used"
but I just tried it on the older gcc48 I have lying around and it worked.
(clang doesn't seem to warn or care about these cases.)

I may use this, since I avoid messing with the make files like the plague.

Thanks, rick
Cy Schubert
2018-06-03 22:06:19 UTC
Permalink
In message <CANCZdfryUsjsqn7izpX9BM354-9013oazxiKAz-***@mail.gma
il.com>
, Warner Losh writes:
> On Sun, Jun 3, 2018 at 3:28 PM, Rick Macklem <***@uoguelph.ca> wrote:
>
> > mmacy has sent me a bunch of warnings of the "variable set but not used"
> > kind
> > generated by gcc8.
> >
> > When I've looked at the code, these are for RPC arguments I parse but do
> > not
> > use at this time.
> > I'd like to leave the code in place, since these arguments may be needed
> > in the
> > future and it is hard to figure out how to get them years from now, when
> > they
> > might be needed.
> > I can think of 3 ways to handle this:
> > 1 - Get rid of the code. (As above, I'd rather not do this.)
> > 2 - Wrap the code with "#if 0"/"#endif" or similar. I'll admit that I find
> > this rather
> > ugly and tends to make the code harder to follow.
> > 3 - Leave the code and add a comment w.r.t. why the variables are set but
> > not used.
> >
> > So, what do others think is the preferable alternative?
> > (Or maybe you have a #4 that seems better than any of these.)
> >
>
> 4. Disable the stupid warning in the Makefile / build system. If you don't
> care, and there's a good reason for what you are doing (sounds like there
> is), better to just disable the warning as so much useless noise.

And leave a comment in the Makefile in case someone decides to
re-enable the warning at some later date.


--
Cheers,
Cy Schubert <***@cschubert.com>
FreeBSD UNIX: <***@FreeBSD.org> Web: http://www.FreeBSD.org

The need of the many outweighs the greed of the few.
Steve Kargl
2018-06-03 22:19:55 UTC
Permalink
On Sun, Jun 03, 2018 at 09:28:47PM +0000, Rick Macklem wrote:
> mmacy has sent me a bunch of warnings of the "variable set but not used" kind
> generated by gcc8.
>
> When I've looked at the code, these are for RPC arguments I parse but do not
> use at this time.
> I'd like to leave the code in place, since these arguments may be needed in the
> future and it is hard to figure out how to get them years from now, when they
> might be needed.
> I can think of 3 ways to handle this:
> 1 - Get rid of the code. (As above, I'd rather not do this.)
> 2 - Wrap the code with "#if 0"/"#endif" or similar. I'll admit that I find this rather
> ugly and tends to make the code harder to follow.
> 3 - Leave the code and add a comment w.r.t. why the variables are set but not used.
>
> So, what do others think is the preferable alternative?
> (Or maybe you have a #4 that seems better than any of these.)
>

CFLAGS+=-Wno-unused

--
Steve
Continue reading on narkive:
Loading...