[Bug c/71152] New: NULL is not cast to (void *) as it ought to be if compiling code with -c
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 $
[Bug c/71152] NULL is not cast to (void *) as it ought to be if compiling code with -c
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71152 --- Comment #1 from Ray Strode --- $ rpm -q gcc gcc-6.0.0-0.20.fc25.x86_64
[Bug c/71152] NULL is not cast to (void *) as it ought to be if compiling code with -c
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71152 --- Comment #2 from Ray Strode --- this test case works as expected with gcc-5.3.1-6.fc23.x86_64
[Bug c/71152] NULL is not cast to (void *) as it ought to be if compiling code with -c
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71152 --- Comment #6 from Ray Strode --- i do indeed seem to have ccache installed, thanks.
[Bug c/65452] New: strcmp (foo, foo) could give a warning
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65452 Bug ID: 65452 Summary: strcmp (foo, foo) could give a warning Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: rstrode at redhat dot com Created attachment 35043 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35043&action=edit example that could warn sometimes gcc will give a warning like: warning: the address of 'foo' will always evaluate as 'true' if the address foo is used in a conditional expression. It would be useful if there was also a warning of the form: warning: the comparison of 'foo' with itself will always evaluate as 'true' if the code does "if (strcmp (foo, foo) == 0)" or similar.
[Bug c/65452] strcmp (foo, foo) could give a warning
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65452 --- Comment #2 from Ray Strode --- probably should catch if (foo == foo) { } type situations too.