__attribute__((warn_unused_result)

Mohanlal Jangir mohanlaljangir@gmail.com
Fri Apr 6 13:39:00 GMT 2007


I tried to use warn_unused_result in following C++ code.

#include <stdio.h>

class myClass {
    public:
    int count() __attribute__((warn_unused_result))
    {
        return printf("hello world\n");
    }
};

int main() {
    myClass obj;
    obj.count();
    return 0;
}

But it is giving compile error.
test.cpp:6: syntax error before `{' token

Could someone tell me how to use this attribute in C++ methods?

bash-2.05b$ g++ -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.3/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--disable-checking --with-system-zlib --enable-__cxa_atexit
--host=i386-redhat-linux
Thread model: posix
gcc version 3.2.3 20030502 (Red Hat Linux 3.2.3-20)

Regards,
Mohan



More information about the Gcc-help mailing list