re PR fortran/51055 (deferred length character allocation: allocate(character(len...
authorTobias Burnus <burnus@net-b.de>
Wed, 23 May 2012 20:35:30 +0000 (22:35 +0200)
committerTobias Burnus <burnus@gcc.gnu.org>
Wed, 23 May 2012 20:35:30 +0000 (22:35 +0200)
2012-05-23  Tobias Burnus  <burnus@net-b.de>

        PR fortran/51055
        PR fortran/45170
        * match.c (gfc_match_allocate): Set length_from_typespec
        for characters.
        * resolve.c (resolve_charlen): If set, don't check whether
        the len is a specification expression.

2012-05-23  Tobias Burnus  <burnus@net-b.de>

        PR fortran/51055
        PR fortran/45170
        * gfortran.dg/allocate_with_typespec_6.f90: New.

From-SVN: r187811

gcc/fortran/ChangeLog
gcc/fortran/match.c
gcc/fortran/resolve.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/allocate_with_typespec_6.f90 [new file with mode: 0644]

index 38bff786afa8734b25a2be452b57c2f21563e369..fe13cc551d4d3711e2f5f2ccfaa2d3853879c388 100644 (file)
@@ -1,3 +1,12 @@
+2012-05-23  Tobias Burnus  <burnus@net-b.de>
+
+       PR fortran/51055
+       PR fortran/45170
+       * match.c (gfc_match_allocate): Set length_from_typespec
+       for characters.
+       * resolve.c (resolve_charlen): If set, don't check whether
+       the len is a specification expression.
+
 2012-05-22  Tobias Burnus  <burnus@net-b.de>
 
        PR fortran/53389
index 3d119180a73a058c6cd1343099a1616d643c284b..93d7fab61b637546981493c80a21fadb893aec42 100644 (file)
@@ -3466,6 +3466,9 @@ gfc_match_allocate (void)
                         "type parameter", &old_locus);
              goto cleanup;
            }
+
+         if (ts.type == BT_CHARACTER)
+           ts.u.cl->length_from_typespec = true;
        }
       else
        {
index 9814c14753af7d5c6ec89a4d03abf951a1f0c681..a56d3f702ef6d01b2ed167410ea84ace85c950a2 100644 (file)
@@ -9945,12 +9945,24 @@ resolve_charlen (gfc_charlen *cl)
 
   cl->resolved = 1;
 
-  specification_expr = 1;
 
-  if (resolve_index_expr (cl->length) == FAILURE)
+  if (cl->length_from_typespec)
     {
-      specification_expr = 0;
-      return FAILURE;
+      if (gfc_resolve_expr (cl->length) == FAILURE)
+       return FAILURE;
+
+      if (gfc_simplify_expr (cl->length, 0) == FAILURE)
+       return FAILURE;
+    }
+  else
+    {
+      specification_expr = 1;
+
+      if (resolve_index_expr (cl->length) == FAILURE)
+       {
+         specification_expr = 0;
+         return FAILURE;
+       }
     }
 
   /* "If the character length parameter value evaluates to a negative
index 35dd366c5e650f4603daa6a4dd0a8b9a15c78720..f337a296910be7a403ec57d2401c9dd2d7beb0af 100644 (file)
@@ -1,3 +1,9 @@
+2012-05-23  Tobias Burnus  <burnus@net-b.de>
+
+       PR fortran/51055
+       PR fortran/45170
+       * gfortran.dg/allocate_with_typespec_6.f90: New.
+
 2012-05-23  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/29185
diff --git a/gcc/testsuite/gfortran.dg/allocate_with_typespec_6.f90 b/gcc/testsuite/gfortran.dg/allocate_with_typespec_6.f90
new file mode 100644 (file)
index 0000000..cd13076
--- /dev/null
@@ -0,0 +1,17 @@
+! { dg-do compile }
+!
+! PR fortran/51055
+! PR fortran/45170 comment 14
+!
+! Contributed by Juha Ruokolainen
+! and Hans-Werner Boschmann
+!
+! gfortran was before checking whether the length
+! was a specification expression.
+!
+
+program a
+  character(len=:), allocatable :: s
+  integer :: i=10
+  allocate(character(len=i)::s)
+end program a