[Bug c++/12668] Strange warnings with -O1 -Wunreachable-code in 3.3.1,3.3.2,3.4
rmerkert at alphatech dot com
gcc-bugzilla@gcc.gnu.org
Sat Oct 18 14:05:00 GMT 2003
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12668
------- Additional Comments From rmerkert at alphatech dot com 2003-10-18 13:51 -------
One more example, where I don't really want to see warning:
cat > test.cpp <<EOF
#include <iostream>
struct Foo {
inline Foo (int x) : foo(0) {init(x); }
private:
inline void init (int x) {
if (x!=0)
foo = x + 1;
}
int foo;
};
struct Z {
Z (int x) : foo(0),z(x) {}
Foo foo;
int z;
};
int main (int argc, int argv)
{
Z z(argc);
::std::cerr << "Z: " << z.z << ::std::endl;
return 0;
}
EOF
g++ -O1 -Wunreachable-code test.cpp
The warning in this case is:
test.cpp: In function `int main(int, int)':
test.cpp:9: warning: will never be executed
There is no unreachable code in the example - it's just that
by choosing a certain parameter, a path in the program does not
need to be executed. That's not the same as being unreachable, that's
optimizing away things.
I've been getting lots of these warnings when I compile with O1 because of this
kind of situation. I think things are just propagated too far down the line.
What if I had 7 nested inlined functions that turn out to be "unreachable".
More information about the Gcc-bugs
mailing list