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