Hello,
I'm facing problems with new behavior in GCC 6.
Let's assume we have trivial program like this:
$ cat assert.c
#include <assert.h>
#include <stddef.h>
__attribute__((nonnull))
int f(char *txt) {
assert(txt != NULL);
return 0;
}
int main(int argc, char **argv) {
return 0;
}
And because upstream is paranoid, it is being compiled with:
$ gcc -Werror -Wall
This code does not compile anymore on Fedora 24:
$ gcc -Werror -Wall assert.c
In file included from assert.c:1:0:
assert.c: In function ‘f’:
assert.c:6:13: error: nonnull argument ‘txt’ compared to NULL [-Werror=nonnull]
assert(txt != NULL);
^
Did anyone met similar problem? What did you do with it?
__attribute__((nonnull)) is tremendously useful for static code analysis and
helped to uncover a lot of (not-yet triggered) issues in the code, so just
removing the attribute would not make me happy.
On the other hand, assert(var != NULL) checks are tremendously useful at
run-time. They detects problems early/near the place when the problem occurred
and makes debugging easier.
gcc -Wno-nonnull -fnodelete-null-pointer-checks
does not sound like the right solution ...
I'm all ears to hear what is the best solution/workaround for this.
--
Petr Spacek @ Red Hat