ysap
ysap

Reputation: 8125

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

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?

Upvotes: 4

Views: 1718

Answers (2)

Chris Eineke
Chris Eineke

Reputation: 386

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

Upvotes: 1

Mats Petersson
Mats Petersson

Reputation: 129524

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

You probably should fix those warnings!

Upvotes: 3

Related Questions