All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Brownell <david-b@pacbell.net>
To: Arjan van de Ven <arjan@infradead.org>
Cc: Jeff Garzik <jeff@garzik.org>, Andrew Morton <akpm@osdl.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] SPI: improve sysfs compiler complaint handling
Date: Thu, 12 Oct 2006 12:07:08 -0700	[thread overview]
Message-ID: <200610121207.08652.david-b@pacbell.net> (raw)
In-Reply-To: <1160678375.3000.454.camel@laptopd505.fenrus.org>

On Thursday 12 October 2006 11:39 am, Arjan van de Ven wrote:
> 
> > Does anyone know why the GCC folk have decided to go against decades
> > of common practice here???
> 
> because it's new semantics. I was involved in this GCC feature (not in
> the coding just in the asking for it) and this behavior was specifically
> requested: It is called __must_check, you MUST CHECK it. It's not the
> normal "unused warning", by putting the attribute on the function you
> tell gcc that the result MUST be checked. Just a cast to void isn't
> checking it.... so it rightfully warns.

Ah, I see.

So another issue would seem to be that this "__must_check" thing is now
being abused ... e.g. in cases like this one, where checking is pointless.

ISTR being frustrated at various points that GCC wouldn't warn when
function values were wrongly ignored.  Seems to me there are at least
four cases for function f() return values:

   f();			/* [1] not used ... worth warning about */

   (void) f();		/* [2] not used, but known to be OK; don't warn */

   value = f();		/* it's "used", assuming [3a] "value" is used
			 * instead of [3b] "value" is not used ... where
			 * "used" means more than just "assigned"
			 */

One of the issues with this __must_check() thing is that it's possible
to shut the warning up by assigning function results to a dummy value,
but then not use that value.  IMO that proliferates bad code.

IMO we'd have been a lot better off with the warnings on [1], which I
never recall seeing, and [3b], which we're clearly not seeing even now.
Because then we could shut up the "safe" warnings cleanly like [2], and
know that the real likely-to-be-bugs cases consistently trigger warnings.

- Dave


      reply	other threads:[~2006-10-12 19:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-10-12  1:49 [PATCH] SPI: improve sysfs compiler complaint handling Jeff Garzik
2006-10-12 18:08 ` David Brownell
2006-10-12 18:24   ` Andrew Morton
2006-10-12 18:46     ` David Brownell
2006-10-12 19:08       ` Arjan van de Ven
2006-10-12 18:39   ` Arjan van de Ven
2006-10-12 19:07     ` David Brownell [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200610121207.08652.david-b@pacbell.net \
    --to=david-b@pacbell.net \
    --cc=akpm@osdl.org \
    --cc=arjan@infradead.org \
    --cc=jeff@garzik.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.