This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[Patch, Fortran] PR fortran/35770: Wrong implicit character typing
- From: Daniel Kraft <d at domob dot eu>
- To: Fortran List <fortran at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 12 Sep 2008 20:49:05 +0200
- Subject: [Patch, Fortran] PR fortran/35770: Wrong implicit character typing
Hi,
when gfc_match_varspec encounters a symbol of yet unknown type, it tries
to type it as IMPLICIT CHARACTER and match a sub-string reference; if
this matching fails, the type spec is reset. This however was
incomplete leading to the problem in PR 35770. The attached patch fixes
this.
The same implicit typing is done for derived types, but only if the
following character is a '%' so I think this is safe as in that case for
the code to be valid the expression must indeed be of a derived type
(correct me if I'm wrong).
With this fix, substring references should be also safe again, as they
can be distinguished from function calls, AFAIK (now I know the reason
for why 1:1 is a valid substring ref but 1 alone is not).
Is there implicit typing of arrays? Like
IMPLICIT INTEGER(5) (a)
So that abc will be an array of 5 integers? I don't think so. But if
this was allowed, there could be another problem with ambiguosity.
Well, enough about those references in general :) It's just I've looked
though this code to check for problems like that in the PR and didn't
come up with any...
Patch is regression testing on GNU/Linux-x86-32. Ok for trunk (and
4.3?) if no regressions?
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-09-12 Daniel Kraft <d@domob.eu>
PR fortran/35770
* primary.c (gfc_match_varspec): Added missing type-spec clearing
after wrong implicit character typing.
2008-09-12 Daniel Kraft <d@domob.eu>
PR fortran/35770
* gfortran.dg/implicit_13.f90: New test.
Index: gcc/fortran/primary.c
===================================================================
--- gcc/fortran/primary.c (revision 140314)
+++ gcc/fortran/primary.c (working copy)
@@ -1869,7 +1869,10 @@ check_substring:
case MATCH_NO:
if (unknown)
- gfc_clear_ts (&primary->ts);
+ {
+ gfc_clear_ts (&primary->ts);
+ gfc_clear_ts (&sym->ts);
+ }
break;
case MATCH_ERROR:
Index: gcc/testsuite/gfortran.dg/implicit_13.f90
===================================================================
--- gcc/testsuite/gfortran.dg/implicit_13.f90 (revision 0)
+++ gcc/testsuite/gfortran.dg/implicit_13.f90 (revision 0)
@@ -0,0 +1,21 @@
+! { dg-do compile }
+
+! PR fortran/35770
+! Implicit declaration hides type of internal function.
+
+! Contributed by Dick Hendrickson <dick.hendrickson@gmail.com>
+
+IMPLICIT CHARACTER (s)
+REAL :: RDA
+
+RDA = S_REAL_SQRT_I(42) ! { dg-bogus "Can't convert" }
+
+CONTAINS
+
+REAL FUNCTION S_REAL_SQRT_I(I) RESULT (R)
+ IMPLICIT NONE
+ INTEGER :: I
+ R = 0.0
+END FUNCTION S_REAL_SQRT_I
+
+END