When compiling with gcc and the -Wunreachable-code flag, gcc warns about every use of the assert macro from <assert.h>. This was reported as a gcc bug (see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22414), but the gcc team declared it to be a glibc bug. Indeed, moving __ASSERT_VOID_CAST inward to apply to the two instances of 0 in assert and assert_perror leaves the assertions working correctly and eliminates the warnings for me. I don't see a place to include a patch on this page, so I'll submit the bug and hope I can attach a patch later.
Created attachment 1163 [details] Proposed patch to assert.h
Changed in CVS.
This patch now raises a new gcc warning when compiling with -W and -pedantic for each assert() with a condition true at compile time. The following code snippet demonstrates the isssue: #include <assert.h> void foo(void) { assert(sizeof(char) == 1); }
I see no problem, it works fine for me.
The warning is only raised with GCC 3.3 (3.3.4), not GCC 4.1 (4.1.1): $ gcc-3.3.4 -c test.c -Wall -pedantic 1.c: In function `foo': 1.c:2: warning: statement with no effect $ gcc-4.1.1 -c 1.c -Wall -pedantic (no warnings)
(In reply to comment #5) > The warning is only raised with GCC 3.3 (3.3.4), not GCC 4.1 (4.1.1): In that case, let's close the bug as fixed since it's working with current GCC.