Bug 2926 - assert macro contains unreachable code
Summary: assert macro contains unreachable code
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: libc (show other bugs)
Version: 2.4
: P3 minor
Target Milestone: ---
Assignee: Ulrich Drepper
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-07-14 19:55 UTC by Jerry James
Modified: 2015-01-29 13:33 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments
Proposed patch to assert.h (390 bytes, patch)
2006-07-14 19:56 UTC, Jerry James
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jerry James 2006-07-14 19:55:13 UTC
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.
Comment 1 Jerry James 2006-07-14 19:56:26 UTC
Created attachment 1163 [details]
Proposed patch to assert.h
Comment 2 Ulrich Drepper 2006-08-03 08:30:15 UTC
Changed in CVS.
Comment 3 Xavier Roche 2007-04-20 08:14:53 UTC
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); }
Comment 4 Ulrich Drepper 2007-05-15 02:55:45 UTC
I see no problem, it works fine for me.
Comment 5 Xavier Roche 2007-06-01 13:33:18 UTC
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)

Comment 6 Andreas Jaeger 2007-06-16 17:27:12 UTC
(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.