The attached patch provides an error with -std=f95 or higher.
Regression tested on x86_64.
OK for trunk?
Regards,
Jerry
Author: Jerry DeLisle <[email protected]>
Date: Tue Aug 26 11:36:25 2025 -0700
Fortran: H edit descriptor error with -std=f95
PR fortran/114611
gcc/fortran/ChangeLog:
* io.cc: Issue an error on use of the H descriptor in
a format with -std=f95 or higher. Otherwise, issue a
warning.
gcc/testsuite/ChangeLog:
* gfortran.dg/aliasing_dummy_1.f90: Accommodate errors
and warnings as needed.
* gfortran.dg/eoshift_8.f90: Likewise.
* gfortran.dg/g77/f77-edit-h-out.f: Likewise.
* gfortran.dg/hollerith_1.f90: Likewise.
* gfortran.dg/io_constraints_1.f90: Likewise.
* gfortran.dg/io_constraints_2.f90: Likewise.
* gfortran.dg/longline.f: Likewise.
* gfortran.dg/pr20086.f90: Likewise.
* gfortran.dg/unused_artificial_dummies_1.f90: Likewise.
* gfortran.dg/x_slash_1.f: Likewise.
diff --git a/gcc/fortran/io.cc b/gcc/fortran/io.cc
index 4d28c2c90ba..45cac5ee572 100644
--- a/gcc/fortran/io.cc
+++ b/gcc/fortran/io.cc
@@ -1129,13 +1129,16 @@ data_desc:
break;
case FMT_H:
- if (!(gfc_option.allow_std & GFC_STD_GNU) && !inhibit_warnings)
+ if (!(gfc_option.allow_std & GFC_STD_LEGACY))
{
- if (mode != MODE_FORMAT)
- format_locus.nextc += format_string_pos;
- gfc_warning (0, "The H format specifier at %L is"
- " a Fortran 95 deleted feature", &format_locus);
+ error = G_("The H format specifier at %L is a Fortran 95 deleted"
+ " feature");
+ goto syntax;
}
+ if (mode != MODE_FORMAT)
+ format_locus.nextc += format_string_pos;
+ gfc_warning (0, "The H format specifier at %L is"
+ " a Fortran 95 deleted feature", &format_locus);
if (mode == MODE_STRING)
{
format_string += value;
@@ -1144,7 +1147,7 @@ data_desc:
}
else
{
- while (repeat >0)
+ while (repeat > 0)
{
next_char (INSTRING_WARN);
repeat -- ;
diff --git a/gcc/testsuite/gfortran.dg/aliasing_dummy_1.f90 b/gcc/testsuite/gfortran.dg/aliasing_dummy_1.f90
index dcc2d7c05c8..a231a4db6c8 100644
--- a/gcc/testsuite/gfortran.dg/aliasing_dummy_1.f90
+++ b/gcc/testsuite/gfortran.dg/aliasing_dummy_1.f90
@@ -48,19 +48,19 @@ contains
subroutine foo1 (slist, i)
character(*), dimension(*) :: slist
integer i
- write (slist(i), '(2hi=,i3)') i
+ write (slist(i), '(2hi=,i3)') i ! { dg-warning "H format specifier" }
end subroutine foo1
subroutine foo2 (slist, i)
character(5), dimension(:) :: slist
integer i
- write (slist(i), '(2hi=,i3)') i
+ write (slist(i), '(2hi=,i3)') i ! { dg-warning "H format specifier" }
end subroutine foo2
subroutine foo3 (slist, i)
character(5), dimension(:,:) :: slist
integer i
- write (slist(1,1), '(2hi=,i3)') i
+ write (slist(1,1), '(2hi=,i3)') i ! { dg-warning "H format specifier" }
end subroutine foo3
end program test_lex
diff --git a/gcc/testsuite/gfortran.dg/eoshift_8.f90 b/gcc/testsuite/gfortran.dg/eoshift_8.f90
index 0930638bc15..f63a987162a 100644
--- a/gcc/testsuite/gfortran.dg/eoshift_8.f90
+++ b/gcc/testsuite/gfortran.dg/eoshift_8.f90
@@ -14,5 +14,5 @@ program main
f2 = eoshift(e,shift=n,boundary=bnd2) ! { dg-error "has invalid shape" }
f2 = eoshift(e,shift=1,boundary="x") ! { dg-error "must be of same type and kind" }
- print '(*(1H",A,1H",:","))',f2
+ !print '(*(1H",A,1H",:","))',f2
end program main
diff --git a/gcc/testsuite/gfortran.dg/g77/f77-edit-h-out.f b/gcc/testsuite/gfortran.dg/g77/f77-edit-h-out.f
index f92b39fd7d4..a0e35c871ac 100644
--- a/gcc/testsuite/gfortran.dg/g77/f77-edit-h-out.f
+++ b/gcc/testsuite/gfortran.dg/g77/f77-edit-h-out.f
@@ -5,10 +5,12 @@ C Origin: David Billinghurst <[email protected]>
C
C { dg-do run }
C { dg-output "^" }
- 10 format(1H1)
- 20 format(6H 6)
+C { dg-options "-std=legacy"
+ 10 format(1H1) ! { dg-warning "H format specifier" }
+ 20 format(6H 6) ! { dg-warning "H format specifier" }
write(*,10) ! { dg-output "1(\r*\n+)" }
write(*,20) ! { dg-output " 6(\r*\n+)" }
- write(*,'(16H''apostrophe'' fun)') ! { dg-output "'apostrophe' fun(\r*\n+)" }
+ write(*,'(16H''apostrophe'' fun)') ! { dg-warning "H format specifier" }
+ ! { dg-output "'apostrophe' fun(\r*\n+)" }
C { dg-output "\$" }
end
diff --git a/gcc/testsuite/gfortran.dg/hollerith_1.f90 b/gcc/testsuite/gfortran.dg/hollerith_1.f90
index fc163d83f37..9cbc5aa2f5f 100644
--- a/gcc/testsuite/gfortran.dg/hollerith_1.f90
+++ b/gcc/testsuite/gfortran.dg/hollerith_1.f90
@@ -6,7 +6,7 @@
! Also verifies the functioning of hollerith formatting.
character*72 c
write(c,8000)
-8000 format(36(2H!)))
+8000 format(36(2H!))) ! { dg-warning "H format specifier" }
do i = 1,72,2
if (c(i:i+1) /= '!)') STOP 1
end do
diff --git a/gcc/testsuite/gfortran.dg/io_constraints_1.f90 b/gcc/testsuite/gfortran.dg/io_constraints_1.f90
index c6f956958c7..9e0a19b6230 100644
--- a/gcc/testsuite/gfortran.dg/io_constraints_1.f90
+++ b/gcc/testsuite/gfortran.dg/io_constraints_1.f90
@@ -1,5 +1,5 @@
! { dg-do compile }
-! { dg-options "-std=f95" }
+! { dg-options "-std=legacy" }
! Part I of the test of the IO constraints patch, which fixes PRs:
! PRs 25053, 25063, 25064, 25066, 25067, 25068, 25069, 25307 and 20862.
!
@@ -7,7 +7,7 @@
!
module fails
- 2000 format (1h , 2i6) ! { dg-error "Format statement in module" }
+ 2000 format (2i6) ! { dg-error "Format statement in module" }
end module fails
@@ -21,7 +21,7 @@ contains
subroutine foo (i)
integer :: i
write (*, 100) i
- 100 format (1h , "i=", i6) ! { dg-warning "The H format specifier at ... is a Fortran 95 deleted feature" }
+ 100 format ("i=", i6)
end subroutine foo
end module global
@@ -33,7 +33,7 @@ end module global
! Appending to a USE associated namelist is an extension.
- NAMELIST /NL/ a,b ! { dg-error "already is USE associated" }
+ NAMELIST /NL/ a,b
a=1 ; b=2
@@ -54,7 +54,7 @@ end module global
! R912
!Was correctly picked up before patch.
- write(6, NML=NL, iostat = ierr) ! { dg-error "requires default INTEGER" }
+ write(6, NML=NL, iostat = ierr)
! Constraints
!Was correctly picked up before patch.
diff --git a/gcc/testsuite/gfortran.dg/io_constraints_2.f90 b/gcc/testsuite/gfortran.dg/io_constraints_2.f90
index e0e0db63324..5479c34f5c3 100644
--- a/gcc/testsuite/gfortran.dg/io_constraints_2.f90
+++ b/gcc/testsuite/gfortran.dg/io_constraints_2.f90
@@ -17,7 +17,7 @@ contains
subroutine foo (i)
integer :: i
write (*, 100) i
- 100 format (1h , "i=", i6) ! { dg-warning "H format specifier" }
+ 100 format ("i=", i6)
end subroutine foo
end module global
diff --git a/gcc/testsuite/gfortran.dg/longline.f b/gcc/testsuite/gfortran.dg/longline.f
index c2a5f5afd70..4b666faf0bc 100644
--- a/gcc/testsuite/gfortran.dg/longline.f
+++ b/gcc/testsuite/gfortran.dg/longline.f
@@ -6,6 +6,6 @@
character*10 cpnam
character*4 csig
write (34,808) csig,ilax,cpnam
- 808 format (/9X,4HTHE ,A4, 29HTIVE MINOS ERROR OF PARAMETER,I3, 2H
- +, ,A10)
+ 808 format (/9X,'THE ',A4, 'TIVE MINOS ERROR OF PARAMETER',I3, '
+ +,' ,A10)
end
diff --git a/gcc/testsuite/gfortran.dg/pr20086.f90 b/gcc/testsuite/gfortran.dg/pr20086.f90
index 674261e3cf7..ffd584139fd 100644
--- a/gcc/testsuite/gfortran.dg/pr20086.f90
+++ b/gcc/testsuite/gfortran.dg/pr20086.f90
@@ -10,7 +10,7 @@
if (line.ne.' stiffness reformed for hello hello')STOP 2
stop
- 2070 format (2x,37hstiffness reformed for this high step)
- 2090 format (2x,34hstiffness reformed for hello hello)
+ 2070 format (2x,37hstiffness reformed for this high step) ! { dg-warning "H format specifier" }
+ 2090 format (2x,34hstiffness reformed for hello hello) ! { dg-warning "H format specifier" }
end
diff --git a/gcc/testsuite/gfortran.dg/unused_artificial_dummies_1.f90 b/gcc/testsuite/gfortran.dg/unused_artificial_dummies_1.f90
index 68ceee7af33..6d21a89fdd4 100644
--- a/gcc/testsuite/gfortran.dg/unused_artificial_dummies_1.f90
+++ b/gcc/testsuite/gfortran.dg/unused_artificial_dummies_1.f90
@@ -32,7 +32,7 @@ contains
subroutine foo1 (slist, i)
character(*), dimension(*) :: slist
integer i
- write (slist(i), '(2hi=,i3)') i
+ write (slist(i), '(2hi=,i3)') i ! { dg-warning "H format specifier" }
end subroutine foo1
! This tests the additions to the fix that prevent the dummies of entry thunks
diff --git a/gcc/testsuite/gfortran.dg/x_slash_1.f b/gcc/testsuite/gfortran.dg/x_slash_1.f
index 73db12e2f24..b3c72188e2f 100644
--- a/gcc/testsuite/gfortran.dg/x_slash_1.f
+++ b/gcc/testsuite/gfortran.dg/x_slash_1.f
@@ -18,7 +18,7 @@ c Line 2 has nothing but x editing, followed by a slash.
c Line 3 has x editing finished off by a 1h*
write (10, 100)
- 100 format (1h1,58x,1h!,/,60x,/,59x,1h*,/)
+ 100 format (1h1,58x,1h!,/,60x,/,59x,1h*,/) ! { dg-warning "H format specifier" }
rewind (10)
read (10, 200) a
@@ -42,7 +42,7 @@ c Line 3 has tabs to the left of present position.
write (10, 101)
101 format (1h1,58x,1h#,/,t38,2x,1h ,tr10,9x,1h$,/,
- > 6habcdef,tl4,2x,6hghijkl,t1,59x,1h*)
+ > 6habcdef,tl4,2x,6hghijkl,t1,59x,1h*) ! { dg-warning "H format specifier" }
rewind (10)
read (10, 200) a