This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [patch, fortran] PR31820 - add warning for implicit conversion of CASE expr
- From: Daniel Franke <franke dot daniel at gmail dot com>
- To: Tobias Burnus <burnus at net-b dot de>
- Cc: gfortran <fortran at gcc dot gnu dot org>, gcc-patches at gcc dot gnu dot org
- Date: Mon, 10 May 2010 18:47:59 +0200
- Subject: Re: [patch, fortran] PR31820 - add warning for implicit conversion of CASE expr
- References: <201005091426.06763.franke.daniel@gmail.com> <4BE7FA53.8010101@net-b.de>
On Monday 10 May 2010 14:21:39 Tobias Burnus wrote:
> On 05/09/2010 02:26 PM, Daniel Franke wrote:
> > select case (i)
> > 1
> >
> > Warning: SELECT CASE expression at (1) converted from INTEGER(1) to
> > INTEGER(4) as at least one CASE value exceeds the range of INTEGER(1)
>
> Frankly, I do not like neither the -W* options nor the message. I think
> the warning should be printed if the case-value exceeds the range of
> allowed values of the case-expr. Unless I have misread your patch, you
> always print a warning if the value is converted, e.g. also for
> SELECT CASE ( integer_1_expr )
> CASE (1) ! default kind, but in the range of integer(1).
I think you got me and the intention of the patch wrong here.
There is no warning for any conversion of any case-value - in the current code
this won't work anyway as the case-values are compared to the already promoted
case-expression. The only warning that's raised is, if any of the case values
has a larger range than the case-expr, and the kind of the latter is promoted
to accomodate for the fact. That this promototion of the case-expression is
The Right Thing (TM) was discussed in PR19168. That we accept different kinds
doesn't matter, as only the type is relevant (CHARACTER aside).
However, you are right that the warning is also printed in above case. The
literal '1' is in the range, but of default kind. Hence, the code that's
already there promotes the case-expr and the warning is raised.
> Additionally, one should consider printing the warning by default - but
> in any case not hidden by the combination of several warning options.
-Wsurprising is enabled by -Wall, hence a "-Wall -Wconversion" works as well.
However, with a range check added, I wouldn't mind a default warning either.
Will look into it again.
Thanks
Daniel