I would like to know if the following piece of code is going to throw an error or a warning upon compilation with any kind of gcc/g++ optimizations enabled.
int a;
a = func();
if (a == 2) {
assert(false);
}
I think the following code can throw a warning "set but unused variable", in release configuration.
int a;
a = func();
assert(a != 2);
But what about the above code? (gcc can remove the if statement itself because nothing is going to be done either in the if-statement or in the if-block (in release build), and then throw a warning "unused but set variable" )
edit : this definitely is not a question regarding reducing the size of code or exe. I want to know a piece of code that succeeds in any build configuration.
edit: we disable assert in release mode
-Wuninitializedis enabled at-O0now (but doesn't work very well, so still doesn't warn on that code, so your point holds)