Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#218 error on make due to warn_unused_result

closed-fixed
None
5
2012-08-27
2012-07-24
Edjunior Machado
No

I've faced the error message below when trying to build upstream oprofile (commit 05b1fb9b158916bf08dfaf0a1e5d41e5f208201a) in a x86 ubuntu 11.10 machine (gcc Ubuntu/Linaro 4.6.1-9ubuntu3):

$ make
...
g++ -DHAVE_CONFIG_H -I. -I../../oprofile.git/pe_profiling -I.. -I ../../oprofile.git/libutil -I ../../oprofile.git/libop -I ../../oprofile.git/libutil++ -I ../../oprofile.git/libperf_events -W -Wall -fno-common -ftemplate-depth-50 -Werror -g -O2 -MT operf.o -MD -MP -MF .deps/operf.Tpo -c -o operf.o ../../oprofile.git/pe_profiling/operf.cpp
../../oprofile.git/pe_profiling/operf.cpp: In function ‘void _handle_sigint(int)’:
../../oprofile.git/pe_profiling/operf.cpp:156:38: error: ignoring return value of ‘ssize_t write(int, const void*, size_t)’, declared with attribute warn_unused_result [-Werror=unused-result]
../../oprofile.git/pe_profiling/operf.cpp: In function ‘int validate_app_name()’:
../../oprofile.git/pe_profiling/operf.cpp:949:34: error: ignoring return value of ‘char* getcwd(char*, size_t)’, declared with attribute warn_unused_result [-Werror=unused-result]
../../oprofile.git/pe_profiling/operf.cpp:954:34: error: ignoring return value of ‘char* getcwd(char*, size_t)’, declared with attribute warn_unused_result [-Werror=unused-result]
../../oprofile.git/pe_profiling/operf.cpp: In function ‘void op_sig_stop(int)’:
../../oprofile.git/pe_profiling/operf.cpp:147:35: error: ignoring return value of ‘ssize_t write(int, const void*, size_t)’, declared with attribute warn_unused_result [-Werror=unused-result]
cc1plus: all warnings being treated as errors

make[2]: *** [operf.o] Error 1
make[2]: Leaving directory `/home/emachado/devel/oprofile/build/pe_profiling'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/emachado/devel/oprofile/build'
make: *** [all] Error 2

The attached patch seems to fix this problem (I'm just not sure about the return codes).

Discussion

  • Modified patch to fix this bug

     
    Attachments
  • Edjunior, could you please test the modified patch I attached.

     
  • Hi Maynard,
    `make` is still failing due to the 2 write() calls:

    g++ -DHAVE_CONFIG_H -I. -I../../oprofile.git/pe_profiling -I.. -I ../../oprofile.git/libutil -I ../../oprofile.git/libop -I ../../oprofile.git/libutil++ -I ../../oprofile.git/libperf_events -W -Wall -fno-common -ftemplate-depth-50 -Werror -g -O2 -MT operf.o -MD -MP -MF .deps/operf.Tpo -c -o operf.o ../../oprofile.git/pe_profiling/operf.cpp
    ../../oprofile.git/pe_profiling/operf.cpp: In function ‘void _handle_sigint(int)’:
    ../../oprofile.git/pe_profiling/operf.cpp:156:45: error: ignoring return value of ‘ssize_t write(int, const void*, size_t)’, declared with attribute warn_unused_result [-Werror=unused-result]
    ../../oprofile.git/pe_profiling/operf.cpp: In function ‘void op_sig_stop(int)’:
    ../../oprofile.git/pe_profiling/operf.cpp:147:42: error: ignoring return value of ‘ssize_t write(int, const void*, size_t)’, declared with attribute warn_unused_result [-Werror=unused-result]
    cc1plus: all warnings being treated as errors

    Thanks,
    Edjunior

     
  • patch to fix the bug using ' attribute ((unused))' variable

     
  • Maynard, just posted a new version of your patch using dummy variables for write() calls that fixes the problem on Ubuntu 11.10 (thanks Peter Bergner and Bill Schmidt for the tip about using "__attribute__ ((__unused__))").

     
  • Thanks, Edjunior. I committed your "op-ubuntu-11.10-v2.patch", with one exception: I removed the cast of the return value from "kill()" since 1) your Ubuntu compiler wasn't actually complaining about the kill call; and 2) the casting to void technique proved ineffective for the write() calls that the compiler *was* complaining about. I had added that cast to void of kill() in the "op-ubuntu-11.10.patch" that I had previously posted for no good reason. It just wasn't necessary or correct, so I removed it.

     
    • assigned_to: nobody --> maynardj
    • status: open --> open-fixed
     
    • status: open-fixed --> closed-fixed