re PR fortran/15963 (Error when comparing characters in restricted expression)
authorTobias Schlüter <tobias.schlueter@physik.uni-muenchen.de>
Tue, 29 Jun 2004 17:01:35 +0000 (19:01 +0200)
committerTobias Schlüter <tobi@gcc.gnu.org>
Tue, 29 Jun 2004 17:01:35 +0000 (19:01 +0200)
fortran/
PR fortran/15963
* expr.c (check_intrinsic_op): Allow comparison of characters.
Make logic easier.

testsuite/
PR fortran/15963
* gfortran.fortran-torture/execute/initialization_1.f90: New test.

From-SVN: r83859

gcc/fortran/ChangeLog
gcc/fortran/expr.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.fortran-torture/execute/initialization_1.f90 [new file with mode: 0644]

index c93c9a49a53c3f9b0c6ebe4c46c086b6f9e35754..9193234effc4cf9fd504282e11f24084b88b5265 100644 (file)
@@ -1,3 +1,9 @@
+2004-06-22  Tobias Schlueter  <tobias.schlueter@physik.uni-muenchen.de>
+
+       PR fortran/15963
+       * expr.c (check_intrinsic_op): Allow comparison of characters.
+       Make logic easier.
+
 2004-06-26  Tobias Schlueter  <tobias.schlueter@physik.uni-muenchen.de>
        Andrew Vaught  <andyv@firstinter.net>
 
index 6abc9244c51a9c4cc5f498c9368cced021948588..e9ed27040eee86ac4183e2afd6c8676d8fcd0b17 100644 (file)
@@ -1167,6 +1167,17 @@ check_intrinsic_op (gfc_expr * e, try (*check_function) (gfc_expr *))
     case INTRINSIC_GE:
     case INTRINSIC_LT:
     case INTRINSIC_LE:
+      if ((*check_function) (e->op2) == FAILURE)
+       return FAILURE;
+      
+      if (!(et0 (e->op1) == BT_CHARACTER && et0 (e->op2) == BT_CHARACTER)
+         && !(numeric_type (et0 (e->op1)) && numeric_type (et0 (e->op2))))
+       {
+         gfc_error ("Numeric or CHARACTER operands are required in "
+                    "expression at %L", &e->where);
+         return FAILURE;
+       }
+      break;
 
     case INTRINSIC_PLUS:
     case INTRINSIC_MINUS:
@@ -1179,10 +1190,8 @@ check_intrinsic_op (gfc_expr * e, try (*check_function) (gfc_expr *))
       if (!numeric_type (et0 (e->op1)) || !numeric_type (et0 (e->op2)))
        goto not_numeric;
 
-      if (e->operator != INTRINSIC_POWER)
-       break;
-
-      if (check_function == check_init_expr && et0 (e->op2) != BT_INTEGER)
+      if (e->operator == INTRINSIC_POWER
+         && check_function == check_init_expr && et0 (e->op2) != BT_INTEGER)
        {
          gfc_error ("Exponent at %L must be INTEGER for an initialization "
                     "expression", &e->op2->where);
index e60bb1e5a53d026bea7d7d6379ed6406896b0284..ae3a5d2c1b009ca3fae491a12d7dcfab15d60004 100644 (file)
@@ -1,3 +1,8 @@
+2004-06-25  Tobias Schlueter  <tobias.schlueter@physik.uni-muenchen.de>
+
+       PR fortran/15963
+       * gfortran.fortran-torture/execute/initialization_1.f90: New test.
+
 2004-06-29  Richard Henderson  <rth@redhat.com>
 
        * gcc.dg/tree-ssa/20040430-1.c: Expect zero if's.
diff --git a/gcc/testsuite/gfortran.fortran-torture/execute/initialization_1.f90 b/gcc/testsuite/gfortran.fortran-torture/execute/initialization_1.f90
new file mode 100644 (file)
index 0000000..2ccb45a
--- /dev/null
@@ -0,0 +1,10 @@
+! PR 15963 -- checks character comparison in initialization expressions
+character(8), parameter :: a(5) = (/ "H", "E", "L", "L", "O" /)
+call x(a)
+contains
+subroutine x(a)
+character(8), intent(in) :: a(:)
+integer :: b(count(a < 'F'))
+if (size(b) /= 1) call abort()
+end subroutine x
+end