]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
fortran [PR122957] DTIO incompatibility with -fdefault-interger-8
authorSteve Kargl <kargl@gcc.gnu.org>
Mon, 22 Dec 2025 02:32:46 +0000 (18:32 -0800)
committerJerry DeLisle <jvdelisle@gcc.gnu.org>
Mon, 22 Dec 2025 21:59:09 +0000 (13:59 -0800)
The -fdefault-integer-8 option is optional to assist with legacy
fortran codes. It is not a Standard 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.

gcc/fortran/interface.cc
gcc/testsuite/gfortran.dg/pr122957.f90 [new file with mode: 0644]

index ef5a17d0af45f0b324141ee39b0e2833b9e4db0b..5ffec5074ed4dd5d05e863c547f3bd0bd44d3eac 100644 (file)
@@ -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 ("Sorry: -fdefault-integer-8 option is not supported 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 (file)
index 0000000..d7b2c5d
--- /dev/null
@@ -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 "is not supported" }
+    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