On Sat, Nov 18, 2023 at 11:12:55PM +0100, Harald Anlauf wrote:
>
> Fortran 2023 added restrictions on integer arguments to SYSTEM_CLOCK.
> The attached patch implements these.
>
> I was struggling with the way we should handle features that are sort-of
> deleted in a new standard, but not described as such in the standard,
> which is why we do not have GFC_STD_F2023_DEL. As -std=gnu should not
> apply this restriction, I came up with the solution in the patch.
> While playing, I hit a gcc_unreachable in notify_std_msg due to a
> missing case, also fixed.
>
> Interestingly, the standard now has a recommendation:
>
> 16.9.202 SYSTEM_CLOCK
>
> It it recommended that all references to SYSTEM_CLOCK use integer
> arguments with a decimal exponent range of at least 18. ...
>
> In case the user chooses integer(4), shall we emit a warning
> e.g. under -pedantic, or some other flag? This is not done
> in the patch, but could be added.
>
> Regtested on x86_64-pc-linux-gnu. OK for mainline?
>
Not in its current form.
> {
> + int first_int_kind = -1;
> + bool f2023 = ((gfc_option.allow_std & GFC_STD_F2023) != 0
> + && (gfc_option.allow_std & GFC_STD_GNU) == 0);
> +
If you use the gfc_notify_std(), then you should not need the
above check on GFC_STD_GNU as it should include GFC_STD_F2023.
>
> + if (f2023 && count->ts.kind < gfc_default_integer_kind)
> + {
> + gfc_error ("Fortran 2023: COUNT argument to SYSTEM_CLOCK "
> + "at %L must have kind of at least default integer",
> + &count->where);
> + return false;
> + }
Elsewhere in the FE, gfortran uses gfc_notify_std() to enforce
requirements of a Fortran standard. The above would be
if (count->ts.kind < gfc_default_integer_kind
&& gfc_notify_std (GFC_STD_F2023, "COUNT argument to SYSTEM_CLOCK "
"at %L must have kind of at least default integer",
&count->where))
Note, gfc_notify_std() should add the 'Fortran 2023: ' string,
if not, that should be fixed.
Of course, I seldom provide patches if others don't have a comment
then do as you like.
--
Steve