https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123693
--- Comment #5 from Steve Kargl <kargl at gcc dot gnu.org> ---
(In reply to Manfred Schwarb from comment #4)
> But why remove something that works even after year 2038?
> It seems that the underlying c-routine works also beyond year 2038.
>
> Relaxing the integer check in gfc_check_ltime_gmtime() and calling
> gmtime_i8 instead of gmtime_i4 in gfc_resolve_gmtime() depending on the
> argument type would make things work, I guess.
>
> I'm not familiar enough with this intrinsic machinery to provide a patch,
> unfortunately.
To begin with, one should not use the -fdefault-* options.
Those options should have been removed years ago. I submitted
a patch to do, but it got voted down.
You'll note that gmtime() does not work with integer(8) unless
it is promoted to default integer kind. Consider the case
where integer(4) is default integer kind, then one sees
% cat foo.f90
program foo
integer(8) val(9)
integer(8) tm
tm = time()
call gmtime(tm, val)
write(*,'(I0)') tm
write(*,'(9(I0,1X))') val
end program foo
% gfcx -o z foo.f90 && ./z
foo.f90:5:16:
5 | call gmtime(tm, val)
| 1
Error: 'time' argument of 'gmtime' intrinsic at (1) must be of kind 4
In the language of Fortran, gmtime() is not a generic subroutine.
It is a specific subroutine expecting the argument to have
types on default integer kind.
% gfcx -o z -fdefault-integer-8 foo.f90 && ./z
1768891041
21 37 6 20 0 126 2 19 0
The option appears to work because of a decades old kludge
to provide gmtime()_i8 if someone was foolish enough to
use the option. The -default-* options break the storage
association rules of Fortran. Among other issues, this has
consequences for Fortran's common and equivalence statements,
and it is known to cause incompatibilities with the runtime
library.
I'll also note that your original example has mixed
precision such as
% cat foo.f90
program foo
integer val(9) ! <-- Default integer kind
integer(8) tm ! <-- Not default integer kind w/o option
tm = time()
call gmtime(tm, val)
write(*,'(I0)') tm
write(*,'(9(I0,1X))') val
end program foo
gmtime_i4i8() and gmtime_i8i4() are not available in the
library. We can (1) add the routines or (2) do type conversion
before and after a function call to gm_time_i8() or (3) document
that the kind of the arguments must match or (4) remove the
functions that are not part of the Fortran standard.