Why do some statements generate warnings in "Release" but not when compiling "Debug" mode with GCC?
I am using gcc to compile some C ++ code, and while the code compiles fine when using the Debug configuration, it gives warnings in the Release configuration. The only difference is in the compilation options:
"Debug": g++ -O0 -g3 ...
"Release": g++ -O3 ...
The message I see in the "Release" build:
../src/xml.cpp: In static member function ‘static Z<char>* XML::ReadToZ(const char*, XMLTransform*, XMLTransformData*)’:
../src/xml.cpp:5034: warning: ignoring return value of ‘size_t fread(void*, size_t, size_t, FILE*)’, declared with attribute warn_unused_result
../src/xml.cpp:5041: warning: ignoring return value of ‘size_t fread(void*, size_t, size_t, FILE*)’, declared with attribute warn_unused_result
Relevant two statements:
/* 5034 */ fread((*y).operator char *(),1,S,fp);
/* 5041 */ fread(yy.operator char *(),1,S,fp);
Why is there a difference in warnings?
+3
source to share
2 answers
This bug report contains the GCC bugzilla bug . Try adding -no-warn-unused-result to your "Release" profile.
+1
source to share