This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch, fortran] PR31820 - add warning for implicit conversion of CASE expr


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]