This is the mail archive of the
mailing list for the GCC project.
Re: [PATCH]: Don't apply default conversions to C switch expressions
- From: "Joseph S. Myers" <jsm28 at cam dot ac dot uk>
- To: Roger Sayle <roger at eyesopen dot com>
- Cc: <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 11 Dec 2001 01:33:44 +0000 (GMT)
- Subject: Re: [PATCH]: Don't apply default conversions to C switch expressions
On Mon, 10 Dec 2001, Roger Sayle wrote:
> From my reading of the draft C99 rationale document, section 126.96.36.199 on
> page 84 states that "case labels are first converted to the type of the
> controlling expression of the switch, then checked for equality with
> other labels." I believe that in the switch statement, "switch (x)",
> the type of the controlling expression is the type of x, possibly an
> "unsigned char" or a enumaral type.
Use the standard, not the Rationale. 188.8.131.52#5 clearly states that "The
integer promotions are performed on the controlling expression.".
> GNU C compiler currently calls "default_conversion" in "c_start_case"
> which promotes these types to integers, which I believe is incorrect
> according to the above document. This patch removes the call to
> "default_conversion" and thereby, I believe, fixes PR c/4475. This
> is a regression from 2.95.
There is in fact a bug present: the subsequent call to get_unwidened. I
previously sent a similar patch, which didn't remove the call to
default_conversion, in an attempt to fix c/2454, but didn't apply it since
it didn't fix that problem at all optimization levels - there seemed still
to be an optimization bug present causing the testcase I included to fail
at -O2, -Os, -O3. No-one familiar with the optimizers answered my request
to look at that part of the problem. Perhaps I should re-test and apply
the patch anyway, since it does still fix a bug, albeit partly.
Joseph S. Myers