re PR fortran/36746 (Rejects variable which is implictly typed as derived typed with...
authorDaniel Kraft <d@domob.eu>
Fri, 5 Sep 2008 11:56:23 +0000 (13:56 +0200)
committerDaniel Kraft <domob@gcc.gnu.org>
Fri, 5 Sep 2008 11:56:23 +0000 (13:56 +0200)
2008-09-05  Daniel Kraft  <d@domob.eu>

PR fortran/36746
* primary.c (gfc_match_rvalue): Removed logic to handle implicit
typing to a derived-type if a component reference is found.
(gfc_match_varspec): Moved it here.

2008-09-05  Daniel Kraft  <d@domob.eu>

PR fortran/36746
* gfortran.dg/implicit_derived_type_1.f90: New test.
* gfortran.dg/used_before_typed_5.f90: New test.

From-SVN: r140034

gcc/fortran/ChangeLog
gcc/fortran/primary.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/implicit_derived_type_1.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/used_before_typed_5.f90 [new file with mode: 0644]

index 459aeb9..d9c65ff 100644 (file)
@@ -1,3 +1,10 @@
+2008-09-05  Daniel Kraft  <d@domob.eu>
+
+       PR fortran/36746
+       * primary.c (gfc_match_rvalue): Removed logic to handle implicit
+       typing to a derived-type if a component reference is found.
+       (gfc_match_varspec): Moved it here.
+
 2008-09-04  Richard Guenther  <rguenther@suse.de>
 
        * trans-array.c (gfc_conv_array_parameter): Use correct types
index 6689443..04c24eb 100644 (file)
@@ -1745,6 +1745,10 @@ gfc_match_varspec (gfc_expr *primary, int equiv_flag, bool sub_flag)
   if (equiv_flag)
     return MATCH_YES;
 
+  if (sym->ts.type == BT_UNKNOWN && gfc_peek_ascii_char () == '%'
+      && gfc_get_default_type (sym, sym->ns)->type == BT_DERIVED)
+    gfc_set_default_type (sym, 0, sym->ns);
+
   if (sym->ts.type != BT_DERIVED || gfc_match_char ('%') != MATCH_YES)
     goto check_substring;
 
@@ -2434,10 +2438,6 @@ gfc_match_rvalue (gfc_expr **result)
     {
     case FL_VARIABLE:
     variable:
-      if (sym->ts.type == BT_UNKNOWN && gfc_peek_ascii_char () == '%'
-         && gfc_get_default_type (sym, sym->ns)->type == BT_DERIVED)
-       gfc_set_default_type (sym, 0, sym->ns);
-
       e = gfc_get_expr ();
 
       e->expr_type = EXPR_VARIABLE;
index ea503fd..4c683eb 100644 (file)
@@ -1,3 +1,9 @@
+2008-09-05  Daniel Kraft  <d@domob.eu>
+
+       PR fortran/36746
+       * gfortran.dg/implicit_derived_type_1.f90: New test.
+       * gfortran.dg/used_before_typed_5.f90: New test.
+
 2008-09-04  Jan Hubicka  <jh@suse.cz>
 
        * gcc.target/i386/cold-attribute-1.c: Update testcase.
diff --git a/gcc/testsuite/gfortran.dg/implicit_derived_type_1.f90 b/gcc/testsuite/gfortran.dg/implicit_derived_type_1.f90
new file mode 100644 (file)
index 0000000..baa36d1
--- /dev/null
@@ -0,0 +1,20 @@
+! { dg-do compile }
+
+! PR fortran/36746
+! Check that parsing of component references for symbols with IMPLICIT
+! derived-type works.
+
+! Reduced test from the PR.
+! Contributed by Tobias Burnus <burnus@gcc.gnu.org>
+
+module m
+  type t
+    integer :: i
+  end type t
+contains
+  subroutine s(x)
+    implicit type(t)(x)
+    dimension x(:)
+    print *, x(1)%i
+  end subroutine s
+end module m
diff --git a/gcc/testsuite/gfortran.dg/used_before_typed_5.f90 b/gcc/testsuite/gfortran.dg/used_before_typed_5.f90
new file mode 100644 (file)
index 0000000..9e78e68
--- /dev/null
@@ -0,0 +1,19 @@
+! { dg-do compile }
+! { dg-options "-pedantic -std=f95" }
+
+! Check that DIMENSION/POINTER/ALLOCATABLE/INTENT statements *do* allow
+! symbols to be typed later.
+
+SUBROUTINE test (a)
+  IMPLICIT REAL (a-z)
+
+  ! Those should *not* IMPLICIT-type the symbols:
+  INTENT(IN) :: a
+  DIMENSION :: b(:)
+  POINTER :: c
+  ALLOCATABLE :: b
+
+  ! So this is ok:
+  INTEGER :: a, b, c
+
+END SUBROUTINE test