[PATCH] Fix -Wswitch (ie. PR c/4475 and PR c++/3780)
Jakub Jelinek
jakub@redhat.com
Mon Feb 4 09:49:00 GMT 2002
On Mon, Feb 04, 2002 at 09:10:21AM -0800, Richard Henderson wrote:
> On Mon, Feb 04, 2002 at 03:42:34PM +0100, Jakub Jelinek wrote:
> > The problem is that SWITCH_COND may be already converted internally by the
> > compiler to some other type (such as int) and thus checking if it is
> > ENUMERAL_TYPE in expand_end_case doesn't work.
>
> Where does this happen? I don't see it. I don't see why it
> should happen either.
c-typeck.c (c_start_case):
type = TYPE_MAIN_VARIANT (TREE_TYPE (exp));
if (warn_traditional && !in_system_header
&& (type == long_integer_type_node
|| type == long_unsigned_type_node))
warning ("`long' switch expression not converted to `int' in ISO C");
exp = default_conversion (exp); <---- here
type = TREE_TYPE (exp);
cp/semantics.c (finish_switch_cond):
if (cond != error_mark_node)
{
cond = default_conversion (cond); <---- and here
cond = fold (build1 (CLEANUP_POINT_EXPR, TREE_TYPE (cond), cond));
}
type = TREE_TYPE (cond);
index = get_unwidened (cond, NULL_TREE);
Checking what gcc-2.96-RH does, it was calling default_conversion as well,
but argument for expand_end_case was passed directly from c-parse.y (thus
the original one, not modified):
| SWITCH '(' expr ')'
{ stmt_count++;
emit_line_note ($<filename>-1, $<lineno>0);
c_expand_start_case ($3); <- default_conversion was done in this function
position_after_white_space (); }
lineno_labeled_stmt
{ expand_end_case ($3); }
Jakub
More information about the Gcc-patches
mailing list