This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/12668] Strange warnings with -O1 -Wunreachable-code in 3.3.1,3.3.2,3.4
- From: "rmerkert at alphatech dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 18 Oct 2003 13:51:14 -0000
- Subject: [Bug c++/12668] Strange warnings with -O1 -Wunreachable-code in 3.3.1,3.3.2,3.4
- References: <20031018040741.12668.rmerkert@alphatech.com>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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".