[Bug c/22414] New: assert(i) gives "will never be executed" due to noreturn

h dot b dot furuseth at usit dot uio dot no gcc-bugzilla@gcc.gnu.org
Mon Jul 11 19:42:00 GMT 2005


assert(i) gives "will never be executed" on Linux.
assert(0) and assert(1) are silent.

I've tried to vary the assert() definition, e.g. give __assert_fail()
return type int and do (void)(i ? 0 : (0 & __assert_fail(...))), but
only removing __attribute__((noreturn)) seems to kill the warning.
I don't want to do that.

gcc configuration:
../gcc-4.0.1/configure --quiet --prefix=/scratch/install
    --program-suffix=-4.0.1 --enable-version-specific-runtime-libs
    --enable-languages=c,c++

bash$ gcc-4.0.1 -save-temps -fsyntax-only -Wunreachable-code foo.cfoo.c: In
function 'Noisy_a':
foo.c:4: warning: will never be executed

bash$ cat -s foo.i
# 1 "foo.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "foo.c"
# 1 "/usr/include/assert.h" 1 3 4
# 36 "/usr/include/assert.h" 3 4
# 1 "/usr/include/features.h" 1 3 4
# 296 "/usr/include/features.h" 3 4
# 1 "/usr/include/sys/cdefs.h" 1 3 4
# 297 "/usr/include/features.h" 2 3 4
# 319 "/usr/include/features.h" 3 4
# 1 "/usr/include/gnu/stubs.h" 1 3 4
# 320 "/usr/include/features.h" 2 3 4
# 37 "/usr/include/assert.h" 2 3 4
# 65 "/usr/include/assert.h" 3 4

extern void __assert_fail (__const char *__assertion, __const char *__file,
      unsigned int __line, __const char *__function)
     __attribute__ ((__noreturn__));

extern void __assert_perror_fail (int __errnum, __const char *__file,
      unsigned int __line,
      __const char *__function)
     __attribute__ ((__noreturn__));

extern void __assert (const char *__assertion, const char *__file, int __line)
     __attribute__ ((__noreturn__));

# 2 "foo.c" 2

void Noisy_a(int i) {
    ((void) ((i) ? 0 : (__assert_fail ("i", "foo.c", 4, __PRETTY_FUNCTION__), 0)));
}
void Silent_b() {
    ((void) ((0) ? 0 : (__assert_fail ("0", "foo.c", 7, __PRETTY_FUNCTION__), 0)));
}
void Silent_c() {
    ((void) ((1) ? 0 : (__assert_fail ("1", "foo.c", 10, __PRETTY_FUNCTION__), 0)));
}

-- 
           Summary: assert(i) gives "will never be executed" due to noreturn
           Product: gcc
           Version: 4.0.1
            Status: UNCONFIRMED
          Severity: minor
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: h dot b dot furuseth at usit dot uio dot no
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22414



More information about the Gcc-bugs mailing list