This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch, Fortran] PR fortran/36746: Fix IMPLICIT typing of derived types


Hi,

so here's my second attempt at this bug, this time with a more conservative patch as promised :)

All I did is moving the logic that gives a symbol it's IMPLICIT derived type if a component reference is found from gfc_match_rvalue to gfc_match_varspec, so that an array-reference inbetween does not confuse the parser. In addition I added a new test to check for the behaviour we agreed upon in the discussion of my last attempt, it succeeds by default.

I've added the reduced test from the PR to the test-suite and also checked that the original test (long) works with my patch. I'm at the moment regression-testing on GNU/Linux-x86-32. Is this patch ok if there are no regressions?

Cheers,
Daniel

--
Done:     Arc-Bar-Cav-Sam-Val-Wiz, Dwa-Elf-Gno-Hum-Orc, Law-Neu-Cha, Fem-Mal
To go:    Hea-Kni-Mon-Pri-Ran-Rog-Tou
2008-08-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-08-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.
Index: gcc/fortran/primary.c
===================================================================
--- gcc/fortran/primary.c	(revision 139985)
+++ gcc/fortran/primary.c	(working copy)
@@ -1745,6 +1745,10 @@ gfc_match_varspec (gfc_expr *primary, in
   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: gcc/testsuite/gfortran.dg/implicit_derived_type_1.f90
===================================================================
--- gcc/testsuite/gfortran.dg/implicit_derived_type_1.f90	(revision 0)
+++ gcc/testsuite/gfortran.dg/implicit_derived_type_1.f90	(revision 0)
@@ -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
Index: gcc/testsuite/gfortran.dg/used_before_typed_5.f90
===================================================================
--- gcc/testsuite/gfortran.dg/used_before_typed_5.f90	(revision 0)
+++ gcc/testsuite/gfortran.dg/used_before_typed_5.f90	(revision 0)
@@ -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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]