This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/20681] [4.0/4.1 Regression] wrong "control reaches" warning with switches
- From: "ian at airs dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 17 Oct 2005 04:39:25 -0000
- Subject: [Bug c++/20681] [4.0/4.1 Regression] wrong "control reaches" warning with switches
- References: <bug-20681-9121@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #11 from ian at airs dot com 2005-10-17 04:39 -------
For the record, this is the work-around in the C frontend:
http://gcc.gnu.org/ml/gcc-patches/2005-01/msg01452.html
A corresponding patch in the C++ frontend would be more complicated, in order
to continue to emit the error "break statement not within loop or switch" when
required.
This class of bugs is a pain to work with at present. The warning just follows
the CFG, which makes sense. But code like
case 1:
return;
break;
builds a CFG which has a return followed by a goto. remove_useless_stmts is
currently not clever enough to remove code after a return, so the goto gets
incorporated into the CFG. Note that we don't get the warning when optimizing;
we only get it with -O0. And indeed when not optimizing the assembly code has
the code path which returns an uninitialized value, although of course it never
gets executed in practice.
Fixing this in the middle-end will require a version of remove_useless_stmts
which is clever enough to efficiently discard statements which follow a return
statement. Andrew was working on that at one point; I don't recall what the
status is.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20681