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
  •  | 
  •  

Frage

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?

War es hilfreich?

Lösung 2

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

Andere Tipps

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

You probably should fix those warnings!

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top