]> git.ipfire.org Git - thirdparty/libvirt.git/commit
build: force correct gcc syntax for attribute_nonnull
authorEric Blake <eblake@redhat.com>
Mon, 18 Feb 2013 20:34:58 +0000 (13:34 -0700)
committerEric Blake <eblake@redhat.com>
Mon, 18 Feb 2013 21:17:40 +0000 (14:17 -0700)
commite086deda3c99a72efa3e4f7acbe17c31d9973bb4
treec1bccd548eba1803eb744adf7dc9006fab3df3e8
parent272be1a84074cdb48e46b866cd9374f097709a2c
build: force correct gcc syntax for attribute_nonnull

Gcc lets you do:

int ATTRIBUTE_NONNULL(1) foo(void *param);
int foo(void *param) ATTRIBUTE_NONNULL(1);
int ATTRIBUTE_NONNULL(1) foo(void *param) { ... }

but chokes on:

int foo(void *param) ATTRIBUTE_NONNULL(1) { ... }

However, since commit eefb881, we have intentionally been disabling
ATTRIBUTE_NONNULL because of lame gcc handling of the attribute (that
is, gcc doesn't do decent warning reporting, then compiles code that
mysteriously fails if you break the contract of the attribute, which
is surprisingly easy to do), leaving it on only for Coverity (which
does a much better job of improved static analysis when the attribute
is present).

But completely eliding the macro makes it too easy to write code that
uses the fourth syntax option, if you aren't using Coverity.  So this
patch forces us to avoid syntax errors, even when not using the
attribute under gcc.  It also documents WHY we disable the warning
under gcc, rather than forcing you to find the commit log.

* src/internal.h (ATTRIBUTE_NONNULL): Expand to empty attribute,
rather than nothing, when on gcc.
src/internal.h