#1371 fix compiler warnings for ignored return values

2.12.0
closed-fixed
5
2008-07-18
2008-05-14
Dan Horak
No

The compiler produces warnings when the return value of a fucntiuon is ignored. It makes problems when compiled with -Werror which is the default.

Discussion

1 2 > >> (Page 1 of 2)
  • Dan Horak
    Dan Horak
    2008-05-14

    remove warnings on ignored return values

     
  • Renier Morales
    Renier Morales
    2008-05-14

    • milestone: --> 761459
    • assigned_to: nobody --> renierm
    • labels: --> Build System
     
  • Renier Morales
    Renier Morales
    2008-05-27

    • milestone: 761459 --> 831933
     
  • Renier Morales
    Renier Morales
    2008-05-27

    Logged In: YES
    user_id=660960
    Originator: NO

    I don't get how can this happen when -Wno-unused-value is being specified after -Wall. Do you know why?

     
  • Dan Horak
    Dan Horak
    2008-05-27

    Logged In: YES
    user_id=8942
    Originator: YES

    I really don't know, why it doesn't work. The only idea I have is that it somehow conflicts with the attribute "warn_unused_result" given to the read/write/... functions in the glibc headers.

    This is my output when compiling without the patch:

    g++ -DHAVE_CONFIG_H -I. -I.. -I../include -I../utils -I../utils -I../marshal -I../ssl -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fno-strict-aliasing -pthread -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -Wall -Wpointer-arith -Wformat=2 -Wformat-security -Wformat-nonliteral -Wcast-qual -Wcast-align -Wshadow -Wwrite-strings -Wredundant-decls -Wno-strict-aliasing -Wno-unused-value -Werror -D_GNU_SOURCE -D_REENTRANT -fexceptions -MT openhpid.o -MD -MP -MF .deps/openhpid.Tpo -c -o openhpid.o openhpid.cpp
    cc1plus: warnings being treated as errors
    openhpid.cpp: In function 'int main(int, char**)':
    openhpid.cpp:229: error: ignoring return value of 'ssize_t write(int, const void*, size_t)', declared with attribute warn_unused_result
    openhpid.cpp: In function 'bool morph2daemon()':
    openhpid.cpp:358: error: ignoring return value of 'ssize_t write(int, const void*, size_t)', declared with attribute warn_unused_result

    I will try to create a minimal example that reveals this behaviour.

     
  • Dan Horak
    Dan Horak
    2008-05-27

    Logged In: YES
    user_id=8942
    Originator: YES

    Believe or not it is affected by the "-O2". Try the attached test script.
    File Added: g

     
  • Dan Horak
    Dan Horak
    2008-05-27

    Logged In: YES
    user_id=8942
    Originator: YES

    Another test case created - when a function is defined with attribute warn_unused_result then using -Wno-unused-value has no effect.
    File Added: g1

     
  • Dan Horak
    Dan Horak
    2008-05-27

    Logged In: YES
    user_id=8942
    Originator: YES

    Including answer from our GCC guru:

    >dhorak< jakub: ping, is it correct that when the result of a function with attribute warn_unused_result is not used, then adding -Wno-unused-value has no effect on the warning that gcc emits?
    -jakub- dhorak: yes, -Wunused-value is unrelated and warn_unused_result attribute warnings are unconditional

     
    • milestone: 831933 --> 831934
    • assigned_to: renierm --> pdphan
     
    • milestone: 831934 --> 2.12.0
     
1 2 > >> (Page 1 of 2)