]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR fortran/28081 (Undue compile-time error for zero-sized substring)
authorFrancois-Xavier Coudert <coudert@clipper.ens.fr>
Sat, 24 Jun 2006 18:10:47 +0000 (20:10 +0200)
committerFrançois-Xavier Coudert <fxcoudert@gcc.gnu.org>
Sat, 24 Jun 2006 18:10:47 +0000 (18:10 +0000)
PR fortran/28081

* resolve.c (resolve_substring): Don't issue out-of-bounds
error messages when the range has zero size.

* gfortran.dg/substr_3.f: New test.
* gfortran.dg/equiv_2.f90: Update expected error message.

From-SVN: r114972

gcc/fortran/ChangeLog
gcc/fortran/resolve.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/equiv_2.f90
gcc/testsuite/gfortran.dg/substr_3.f [new file with mode: 0644]

index af4b5e96f5258cb1e68c6ba9cb666b4a8877ff71..6e5e492aa1175a7d612601a86d54dbe5029d878f 100644 (file)
@@ -1,3 +1,9 @@
+2006-06-24  Francois-Xavier Coudert  <coudert@clipper.ens.fr>
+
+       PR fortran/28081
+       * resolve.c (resolve_substring): Don't issue out-of-bounds
+       error messages when the range has zero size.
+
 2006-06-24  Francois-Xavier Coudert  <coudert@clipper.ens.fr>
 
        PR fortran/23862
index 384b5a4e343de8dea44c582764e78ba48b8d8e08..fe37f2cbeb015dec599863bd57faa22091631f3a 100644 (file)
@@ -2542,7 +2542,9 @@ resolve_substring (gfc_ref * ref)
          return FAILURE;
        }
 
-      if (compare_bound_int (ref->u.ss.start, 1) == CMP_LT)
+      if (compare_bound_int (ref->u.ss.start, 1) == CMP_LT
+         && (compare_bound (ref->u.ss.end, ref->u.ss.start) == CMP_EQ
+             || compare_bound (ref->u.ss.end, ref->u.ss.start) == CMP_GT))
        {
          gfc_error ("Substring start index at %L is less than one",
                     &ref->u.ss.start->where);
@@ -2570,9 +2572,11 @@ resolve_substring (gfc_ref * ref)
        }
 
       if (ref->u.ss.length != NULL
-         && compare_bound (ref->u.ss.end, ref->u.ss.length->length) == CMP_GT)
+         && compare_bound (ref->u.ss.end, ref->u.ss.length->length) == CMP_GT
+         && (compare_bound (ref->u.ss.end, ref->u.ss.start) == CMP_EQ
+             || compare_bound (ref->u.ss.end, ref->u.ss.start) == CMP_GT))
        {
-         gfc_error ("Substring end index at %L is out of bounds",
+         gfc_error ("Substring end index at %L exceeds the string length",
                     &ref->u.ss.start->where);
          return FAILURE;
        }
index 2db5a7c6c7860c6c88f75d2ff56caefd25c8ee5a..a8598aa4f92e4951190fd8e8e35a17e6ff44631b 100644 (file)
@@ -1,3 +1,9 @@
+2006-06-24  Francois-Xavier Coudert  <coudert@clipper.ens.fr>
+
+       PR fortran/28081
+       * gfortran.dg/substr_3.f: New test.
+       * gfortran.dg/equiv_2.f90: Update expected error message.
+
 2006-06-24  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/28118
index c827aecb89aa70d393fdd436163254fa4c127f4c..8bc7fb14ac7ec6c783e89d25eba8e8536915ff7c 100644 (file)
@@ -7,7 +7,7 @@
       subroutine broken_equiv2
       character*4 j
       character*2 k
-      equivalence (j(2:3), k(1:5))    ! { dg-error "out of bounds" }
+      equivalence (j(2:3), k(1:5))    ! { dg-error "exceeds the string length" }
       end subroutine
 
       subroutine broken_equiv3
diff --git a/gcc/testsuite/gfortran.dg/substr_3.f b/gcc/testsuite/gfortran.dg/substr_3.f
new file mode 100644 (file)
index 0000000..3bb7197
--- /dev/null
@@ -0,0 +1,12 @@
+! { dg-do run }
+! Check that substrings behave correctly even when zero-sized
+      implicit none
+      character(len=10) :: s, t
+      integer :: i, j
+
+      s = "abcdefghij"
+      t(:10) = s(1:)
+      s(16:15) = "foo"
+      s(0:-1) = "foo"
+      if (s /= t) call abort
+      end