This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/31246] Strange -Wunreachable-code warning with _GLIBCXX_DEBUG
- From: "pinskia at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 19 Mar 2007 22:31:02 -0000
- Subject: [Bug c++/31246] Strange -Wunreachable-code warning with _GLIBCXX_DEBUG
- References: <bug-31246-1902@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #11 from pinskia at gcc dot gnu dot org 2007-03-19 22:31 -------
(In reply to comment #10)
>
> I fully agree.
I am not agreeing fully, This warning is only because we can prove something
is pure/const/cannot throw and that only comes because of simple optimization.
What about this case:
int f(int a) { return a;}
int g(int b)
{
try
{
return f(b);
}catch (...) { return 0; }
}
Should we warn about the catch being unreachable?
This is the same issue as -Wuninitialized warning in that we warn about a lot
of cases where we should not. I think this is why this option is not turned on
via either -W or -Wall, it is hard sometimes to work around.
Take even more extrem example where templates come into play:
int f(int a) { return a;}
int f(float a);
template <typename a>
int g(a b)
{
try
{
return f(a);
}catch (...) { return 0; }
}
int d = g<int>(10);
Should we warn that the catch case is unreachable, I think so as it is obvious
but how do we avoid it, well you can specialize the template but that could get
messy.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31246