[Bug c/71152] New: NULL is not cast to (void *) as it ought to be if compiling code with -c
rstrode at redhat dot com
gcc-bugzilla@gcc.gnu.org
Mon May 16 19:20:00 GMT 2016
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71152
Bug ID: 71152
Summary: NULL is not cast to (void *) as it ought to be if
compiling code with -c
Product: gcc
Version: 6.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: rstrode at redhat dot com
Target Milestone: ---
Created attachment 38499
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=38499&action=edit
small test case try compiling with -c and without
I was refactoring code in a project and moved some code off to a helper
function.
The helper function returns an integer error code and the main function returns
a pointer.
When I moved the error handling code over from the main function to the helper
function, I neglected to change the return code from NULL to -1.
gcc didn't warn about this.
So I wrote a quick test case (attached) and discovered something very strange.
gcc does warn if you compile and link the code in one step, i.e.:
$ gcc nulltest.c
nulltest.c: In function ‘NULL_as_int’:
nulltest.c:6:12: warning: return makes integer from pointer without a cast
[-Wint-conversion]
return NULL;
^~~~
$
But if you pass -c to defer linking, the bug manifests:
$ gcc nulltest.c -c
$
More information about the Gcc-bugs
mailing list