This is the mail archive of the gcc-help@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]

warn on unused result without attribute warn_unused_result


Hello gcc contributors.

I had an issue which was ultimately caused by not using the return
value of a function and I'm trying to find a compile-time warning that
could have alerted me to the issue.

I've been looking through the documentation but I'm not seeing a
compile-time warning flag about ignoring function return values. Sure,
I can add the attribute "warn_unused_result" but I'm wondering if the
same affect is possible (i.e., for all functions) without changing any
code. I feel like this must have come up before and there's a reason
this warning doesn't exist -- perhaps this is better handled by a
static analysis tool, or perhaps it generates too much noise -- but if
there was a previous discussion about this I'd appreciate being
pointed in that direction. Or perhaps I'm just not searching for the
right terms, in which case I apologize for taking your time.

Example below, in which I try a few different compiler warning options
but none of which produce a warning.

burnsba@p-debian:~/code/gcc_help$ cat simple_example.c
#include <stdio.h>

int func(int a)
{
    return a + 2;
}

inline int inline_func(int a)
{
    return a + 2;
}

int main()
{
    int b=0;
    scanf("%d", &b);
    func(b);
    inline_func(b);
    return 0;
}

burnsba@p-debian:~/code/gcc_help$ gcc -Wall -Wextra -pedantic
-Wunused-function -Wunused-parameter -Wunused-value -Winline
-Wunused-result -O0 simple_example.c
burnsba@p-debian:~/code/gcc_help$
burnsba@p-debian:~/code/gcc_help$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i586-linux-gnu/4.9/lto-wrapper
Target: i586-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian
4.9.2-10' --with-bugurl=file:///usr/share/doc/gcc-4.9/README.Bugs
--enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-4.9 --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.9
--libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes
--enable-gnu-unique-object --disable-vtable-verify --enable-plugin
--with-system-zlib --disable-browser-plugin --enable-java-awt=gtk
--enable-gtk-cairo
--with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.9-i386/jre
--enable-java-home
--with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.9-i386
--with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.9-i386
--with-arch-directory=i386
--with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc
--enable-targets=all --enable-multiarch --with-arch-32=i586
--with-multilib-list=m32,m64,mx32 --enable-multilib
--with-tune=generic --enable-checking=release --build=i586-linux-gnu
--host=i586-linux-gnu --target=i586-linux-gnu
Thread model: posix
gcc version 4.9.2 (Debian 4.9.2-10)


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