Re: [notmuch] [PATCH 1/2] * avoid gcc 4.4.1 compiler warnings due to ignored write return values

Subject: Re: [notmuch] [PATCH 1/2] * avoid gcc 4.4.1 compiler warnings due to ignored write return values

Date: Tue, 01 Dec 2009 07:57:30 -0800

To: Jed Brown, Karl Wiberg, Dirk-Jan Binnema

Cc: notmuch@notmuchmail org, djcb@djcbsoftware.nl

From: Carl Worth


On Mon, 23 Nov 2009 15:24:46 +0100, Jed Brown <jed@59A2.org> wrote:
> >From the gcc man page:
> 
>        -Wunused-value
>            Warn whenever a statement computes a result that is explicitly
>            not used. To suppress this warning cast the unused expression
>            to void. This includes an expression-statement or the left-
>            hand side of a comma expression that contains no side effects.
>            For example, an expression such as x[i,j] will cause a
>            warning, while x[(void)i,j] will not.
> 
>            This warning is enabled by -Wall.
> 
> But I'm confused here because I don't currently see any warnings with
> gcc-4.4.2.  Actually this must be a bug because I get no warnings for
> the blatantly unused
> 
>   malloc(5);

I'm guessing that the -Wunused-value warning doesn't consider values
computed by function calls.

> with -Wall -Wextra -pedantic.  Anyway, if your system headers specify
> __attribute__((warn_unused_result)) for write, then you could be running
> into this bug/feature
> 
>   http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35579

Yes, this is the attribute that's triggering the warnings. I poked
around in the glibc headers to see how to get this warning myself, and I
finally found:

	make CFLAGS="-O -D_FORTIFY_SOURCE"

That makes the warning appear even with gcc 4.3.4, (and the definitions
in the headers suggest it will work with any gcc >= 4.1).

So I've pushed the patch now, (with an updated commit message to reflect
the above analysis).

-Carl
part-000.sig (application/pgp-signature)

Thread: