Aw: Re: [PATCH] PR fortran/97408 - Diagnose non-constant KIND argument to intrinsics

2020-10-14 Thread Harald Anlauf
Hi Tobias,

> > The KIND argument to intrinsics must be a compile-time argument.
> > Improve check so that the proper diagnostics is emitted.
> >
> >
> > -  if (!gfc_check_init_expr (k))
> > +  if (!gfc_check_init_expr (k) || k->expr_type == EXPR_VARIABLE)
> 
> I think the real question is why is the following regarded as initialization 
> expression:
>t = true;
> …
>if (gfc_check_iter_variable (e))
>  break;

you completely lost me here.  Did you accidentally delete some context?

> Or worded differently: If
>integer, parameter :: A(*) = [(i, i=1,5)]
> is valid, which should
>integer, parameter :: B(*) = [integer :: (int(i, kind=i), i=1,2)]
> be invalid?

Well, my copy of the F2018-FDIS says about the KIND argument to INT:

"KIND (optional) shall be a scalar integer constant expression."

Are you saying that (int(i, kind=i), i=1,2) is legal?
It would be helpful if you explained why "i" in kind=i is a constant expression.

> Thus, the first question should be whether that is valid code
> according to the Fortran standard or not.

Indeed.

Harald



Re: Aw: Re: [PATCH] PR fortran/97408 - Diagnose non-constant KIND argument to intrinsics

2020-10-14 Thread Tobias Burnus

Hi Harald,

On 10/14/20 8:25 PM, Harald Anlauf wrote:

Or worded differently: If
integer, parameter :: A(*) = [(i, i=1,5)]
is valid, which should
integer, parameter :: B(*) = [integer :: (int(i, kind=i), i=1,2)]
be invalid?

Well, my copy of the F2018-FDIS says about the KIND argument to INT:
"KIND (optional) shall be a scalar integer constant expression."

Which applies to "B". For "A" (PARAMETER) it states: "entity has the
value specified byits constant-expr,"

Are you saying that (int(i, kind=i), i=1,2) is legal?
It would be helpful if you explained why "i" in kind=i is a constant expression.

I only say that it might be valid. – It would be likewise helpful if you
could explain why "i" is a const-expr in "[(i, i=1,5)]" – which we agree
is valid, don't we?. And what about "i" in "int(i)" for "[(kind(i),
i=1,5)]"?

I don't know whether it is valid – I just find it not obvious that [(i,
i=1,5)] is valid and [(int(1, kind=i), i=1,1)] is not.

Surely, if one first expands the array, it is valid: "[integer ::
(int(i, kind=i), i=1,2)]" → "[integer :: int(1, kind=1), int(2,kind=2)]"
→ "[integer :: 1_1, 2_2]" → "[1,2]".

In any case, gfc_check_init_expr is supposed to check for const-expr –
and if that does not work, gfc_check_init_expr should be fixed or at
least clearly understood when it can be used and when it cannot be used.

Tobias

-
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander 
Walter