This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/67730] New: [5.2 Regression] No warning when returning NULL in void function


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67730

            Bug ID: 67730
           Summary: [5.2 Regression] No warning when returning NULL in
                    void function
           Product: gcc
           Version: 5.2.0
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: damwdan at gmail dot com
  Target Milestone: ---

Created attachment 36401
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36401&action=edit
preprocessed source file

Following up on this Stackoverflow post:
http://stackoverflow.com/q/32732281/5366270

There seems to be a regression in gcc 5.2.0. When returning NULL in a void
function, gcc *does not* warn or error. gcc 4.9.2 (and some other previous
versions, as mentioned in the post) warns. clang 3.7 errors. As noted by "Marc
Glisse", using -Wsystem-headers does the trick and generates a warning. Though,
the preprocessed output (attached) is exactly the same.

$ cat c.c
#include <stddef.h>

void procedure(void)
{
    return NULL;
}
$ gcc -Wall -Wextra -std=c99 -pedantic -c c.c
$ gcc -Wall -Wextra -std=c99 -pedantic -Wsystem-headers -c c.c
In file included from c.c:1:0:
c.c: In function âprocedureâ:
c.c:5:12: warning: âreturnâ with a value, in function returning void
     return NULL;
            ^
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-unknown-linux-gnu/5.2.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /build/gcc-multilib/src/gcc-5.2.0/configure --prefix=/usr
--libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man
--infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/
--enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared
--enable-threads=posix --enable-libmpx --with-system-zlib --with-isl
--enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu
--disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object
--enable-linker-build-id --enable-lto --enable-plugin
--enable-install-libiberty --with-linker-hash-style=gnu
--enable-gnu-indirect-function --enable-multilib --disable-werror
--enable-checking=release --with-default-libstdcxx-abi=gcc4-compatible
Thread model: posix
gcc version 5.2.0 (GCC) 

Note that the bug also appears when returning NULL in an int or char function,
but not double (an error is generated).

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]