The attached patch from Steve issues an error if a user trys to use DTIO with -fdefault-integer-8. I reduced the test case and set it up for the testsuite. Some may think this is a bit harsh, but one would get silent wrong results otherwise.
Regression tested on x86_64. OK for mainline? Regards, Jerry Author: Steve Kargl <[email protected]> Date: Sun Dec 21 18:32:46 2025 -0800 fortran [PR122957] DTIO incompatibility with -fdefault-interger-8 The -fdefault-integer-8 option is optional to assist with legacy fortran codes. It is not a Stndard requirement and is not compatible with the newer user defined derived type I/O. PR fortran/122957 gcc/fortran/ChangeLog: * interface.cc (gfc_match_generic_spec): Issue an error so that users do not use -fdefault-integer-8 with DTIO. gcc/testsuite/ChangeLog: * gfortran.dg/pr122957.f90: New test.
commit b12ec7a65fe9d9fd0763ccd4adece9f84192e325 Author: Steve Kargl <[email protected]> Date: Sun Dec 21 18:32:46 2025 -0800 fortran [PR122957] DTIO incompatibility with -fdefault-interger-8 The -fdefault-integer-8 option is optional to assist with legacy fortran codes. It is not a Stndard requirement and is not compatible with the newer user defined derived type I/O. PR fortran/122957 gcc/fortran/ChangeLog: * interface.cc (gfc_match_generic_spec): Issue an error so that users do not use -fdefault-integer-8 with DTIO. gcc/testsuite/ChangeLog: * gfortran.dg/pr122957.f90: New test. diff --git a/gcc/fortran/interface.cc b/gcc/fortran/interface.cc index ef5a17d0af4..6ed01e2cee9 100644 --- a/gcc/fortran/interface.cc +++ b/gcc/fortran/interface.cc @@ -211,11 +211,15 @@ gfc_match_generic_spec (interface_type *type, *op = dtio_op (buffer); if (*op == INTRINSIC_FORMATTED) { + if (flag_default_integer) + goto conflict; strcpy (name, gfc_code2string (dtio_procs, DTIO_RF)); *type = INTERFACE_DTIO; } if (*op == INTRINSIC_UNFORMATTED) { + if (flag_default_integer) + goto conflict; strcpy (name, gfc_code2string (dtio_procs, DTIO_RUF)); *type = INTERFACE_DTIO; } @@ -228,11 +232,15 @@ gfc_match_generic_spec (interface_type *type, *op = dtio_op (buffer); if (*op == INTRINSIC_FORMATTED) { + if (flag_default_integer) + goto conflict; strcpy (name, gfc_code2string (dtio_procs, DTIO_WF)); *type = INTERFACE_DTIO; } if (*op == INTRINSIC_UNFORMATTED) { + if (flag_default_integer) + goto conflict; strcpy (name, gfc_code2string (dtio_procs, DTIO_WUF)); *type = INTERFACE_DTIO; } @@ -250,6 +258,11 @@ gfc_match_generic_spec (interface_type *type, *type = INTERFACE_NAMELESS; return MATCH_YES; +conflict: + gfc_error ("-fdefault-integer-8 option conflicts with user-defined " + "input/output at %C"); + return MATCH_ERROR; + syntax: gfc_error ("Syntax error in generic specification at %C"); return MATCH_ERROR; diff --git a/gcc/testsuite/gfortran.dg/pr122957.f90 b/gcc/testsuite/gfortran.dg/pr122957.f90 new file mode 100644 index 00000000000..dcebd030d7a --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr122957.f90 @@ -0,0 +1,22 @@ +! { dg-do compile } +! { dg-options "-fdefault-integer-8" } + +module mymod + type :: my_type + real :: value + end type + + interface write(formatted) ! { dg-error "conflicts with" } + module procedure write_formatted ! { dg-error "a generic module interface" } + end interface ! { dg-error "Expecting" } + +contains + subroutine write_formatted(dtv, unit, iotype, v_list, iostat, iomsg) + class(my_type), intent(in) :: dtv + integer, intent(in) :: unit + character(*), intent(in) :: iotype + integer, intent(in) :: v_list(:) + integer, intent(out) :: iostat + character(*), intent(inout) :: iomsg + end subroutine write_formatted +end module
