Why do some statements generate warnings in "Release" but not in "Debug" mode compilation with GCC?

StackOverflow https://stackoverflow.com/questions/14513850

  •  17-01-2022
  •  | 
  •  

문제

I am using gcc to compile some C++ code, and while the code compiles fine when using "Debug" configuration, it emits warnings in "Release" configuration. The only difference in the compile options is:

"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

The relevant two statements are:

/* 5034 */ fread((*y).operator char *(),1,S,fp);
/* 5041 */ fread(yy.operator char *(),1,S,fp);

Why is there a difference in warnings?

도움이 되었습니까?

해결책 2

There's a bug report at the GCC bugzilla about this behaviour. Try adding --no-warn-unused-result to your "Release" profile.

다른 팁

Some warnings are generated based on "flow analysis", which is something the compiler does during certain optimisation steps.

You probably should fix those warnings!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top