re PR fortran/25045 ([4.1 only] DIM argument of PRODUCT is not optional)
authorThomas Koenig <Thomas.Koenig@online.de>
Tue, 14 Feb 2006 19:25:36 +0000 (19:25 +0000)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Tue, 14 Feb 2006 19:25:36 +0000 (19:25 +0000)
2006-02-14  Thomas Koenig  <Thomas.Koenig@online.de>

        PR fortran/25045
        * check.c (dim_check):  Perform all checks if dim is optional.
        (gfc_check_minloc_maxloc):  Use dim_check and dim_rank_check
        to check dim argument.
        (check_reduction):  Likewise.

2006-02-14  Thomas Koenig  <Thomas.Koenig@online.de>

        PR fortran/25045
        * optional_dim.f90:  New test.

From-SVN: r110994

gcc/fortran/ChangeLog
gcc/fortran/check.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/optional_dim.f90 [new file with mode: 0644]

index faf6975e2dfd24ba1b1bb20efa77d03671e9b603..4cff233a4e937d49662e49fde890819940d7e9c4 100644 (file)
@@ -1,3 +1,11 @@
+2006-02-14  Thomas Koenig  <Thomas.Koenig@online.de>
+
+        PR fortran/25045
+        * check.c (dim_check):  Perform all checks if dim is optional.
+        (gfc_check_minloc_maxloc):  Use dim_check and dim_rank_check
+        to check dim argument.
+        (check_reduction):  Likewise.
+
 2006-02-14  Tobias Schl\81üter  <tobias.schlueter@physik.uni-muenchen.de>
 
        PR fortran/26277
index dc6541c85980ddd103a3f700764660bdb14f3173..6d3fd3d825e52de4e499b9d4a45cf0a57d90bb05 100644 (file)
@@ -295,16 +295,8 @@ variable_check (gfc_expr * e, int n)
 static try
 dim_check (gfc_expr * dim, int n, int optional)
 {
-  if (optional)
-    {
-      if (dim == NULL)
-       return SUCCESS;
-
-      if (nonoptional_check (dim, n) == FAILURE)
-       return FAILURE;
-
-      return SUCCESS;
-    }
+  if (optional && dim == NULL)
+    return SUCCESS;
 
   if (dim == NULL)
     {
@@ -319,6 +311,9 @@ dim_check (gfc_expr * dim, int n, int optional)
   if (scalar_check (dim, n) == FAILURE)
     return FAILURE;
 
+  if (nonoptional_check (dim, n) == FAILURE)
+    return FAILURE;
+
   return SUCCESS;
 }
 
@@ -1578,9 +1573,10 @@ gfc_check_minloc_maxloc (gfc_actual_arglist * ap)
       ap->next->next->expr = m;
     }
 
-  if (d != NULL
-      && (scalar_check (d, 1) == FAILURE
-      || type_check (d, 1, BT_INTEGER) == FAILURE))
+  if (dim_check (d, 1, 1) == FAILURE)
+    return FAILURE;
+
+  if (dim_rank_check (d, a, 0) == FAILURE)
     return FAILURE;
 
   if (m != NULL && type_check (m, 2, BT_LOGICAL) == FAILURE)
@@ -1634,9 +1630,10 @@ check_reduction (gfc_actual_arglist * ap)
       ap->next->next->expr = m;
     }
 
-  if (d != NULL
-      && (scalar_check (d, 1) == FAILURE
-      || type_check (d, 1, BT_INTEGER) == FAILURE))
+  if (dim_check (d, 1, 1) == FAILURE)
+    return FAILURE;
+
+  if (dim_rank_check (d, a, 0) == FAILURE)
     return FAILURE;
 
   if (m != NULL && type_check (m, 2, BT_LOGICAL) == FAILURE)
index cb15ef61fec5b15906d4787fa66a39eb3bfc6ce6..5d4bfafd87f9ddda0c0fb10084e1996d842fcbc0 100644 (file)
@@ -1,3 +1,8 @@
+2006-02-14  Thomas Koenig  <Thomas.Koenig@online.de>
+
+        PR fortran/25045
+        * optional_dim.f90:  New test.
+
 2006-02-14  Tobias Schlüter  <tobias.schlueter@physik.uni-muenchen.de>
 
        PR fortran/26277
diff --git a/gcc/testsuite/gfortran.dg/optional_dim.f90 b/gcc/testsuite/gfortran.dg/optional_dim.f90
new file mode 100644 (file)
index 0000000..dd201fb
--- /dev/null
@@ -0,0 +1,10 @@
+! { dg-do compile }
+subroutine foo(a,n)
+  real, dimension(2) :: a
+  integer, optional :: n
+  print *,maxloc(a,dim=n) ! { dg-error "must not be OPTIONAL" }
+  print *,maxloc(a,dim=4) ! { dg-error "is not a valid dimension index" }
+  print *,maxval(a,dim=n) ! { dg-error "must not be OPTIONAL" }
+  print *,maxval(a,dim=4) ! { dg-error "is not a valid dimension index" }
+end subroutine foo
+