diff mbox

[Fortran] PR 52325 - Better diagnostic for <unknown>%component

Message ID 4F43BE5D.8040609@net-b.de
State New
Headers show

Commit Message

Tobias Burnus Feb. 21, 2012, 3:55 p.m. UTC
Build and regtested on x86-64-linux.
OK for the 4.8 trunk?

Tobias

Comments

Mikael Morin Feb. 27, 2012, 7:25 p.m. UTC | #1
On Tuesday 21 February 2012 16:55:09 Tobias Burnus wrote:
> Build and regtested on x86-64-linux.
> OK for the 4.8 trunk?
> 
OK.

Mikael

PS: I think that, in general, we should _accept_ statements on MATCH_ERROR to 
avoid issues of this kind.
diff mbox

Patch

2012-02-21  Tobias Burnus  <burnus@net-b.de>

	PR fortran/52325
	* primary.c (gfc_match_varspec): Add diagnostic for % with
	nonderived types.

2012-02-21  Tobias Burnus  <burnus@net-b.de>

	PR fortran/52325
	* gfortran.dg/derived_comp_array_ref_8.f90: New.
	* gfortran.dg/nullify_2.f90: Update dg-error.
	* gfortran.dg/nullify_4.f90: Ditto.
	* gfortran.dg/pointer_init_6.f90: Ditto.

Index: gcc/fortran/primary.c
===================================================================
--- gcc/fortran/primary.c	(revision 184439)
+++ gcc/fortran/primary.c	(working copy)
@@ -1910,6 +1910,19 @@  gfc_match_varspec (gfc_expr *primary, int equiv_fl
       && gfc_get_default_type (sym->name, sym->ns)->type == BT_DERIVED)
     gfc_set_default_type (sym, 0, sym->ns);
 
+  if (sym->ts.type == BT_UNKNOWN && gfc_match_char ('%') == MATCH_YES)
+    {
+      gfc_error ("Symbol '%s' at %C has no IMPLICIT type", sym->name);
+      return MATCH_ERROR;
+    }
+  else if ((sym->ts.type != BT_DERIVED && sym->ts.type != BT_CLASS)
+	   && gfc_match_char ('%') == MATCH_YES)
+    {
+      gfc_error ("Unexpected '%%' for nonderived-type variable '%s' at %C",
+		 sym->name)
+      return MATCH_ERROR;
+    }
+
   if ((sym->ts.type != BT_DERIVED && sym->ts.type != BT_CLASS)
       || gfc_match_char ('%') != MATCH_YES)
     goto check_substring;
Index: gcc/testsuite/gfortran.dg/derived_comp_array_ref_8.f90
===================================================================
--- gcc/testsuite/gfortran.dg/derived_comp_array_ref_8.f90	(revision 0)
+++ gcc/testsuite/gfortran.dg/derived_comp_array_ref_8.f90	(working copy)
@@ -0,0 +1,8 @@ 
+! { dg-do compile }
+!
+! PR fortran/52325
+!
+real :: f
+cc%a = 5 ! { dg-error "Symbol 'cc' at .1. has no IMPLICIT type" }
+f%a = 5  ! { dg-error "Unexpected '%' for nonderived-type variable 'f' at" }
+end
Index: gcc/testsuite/gfortran.dg/nullify_2.f90
===================================================================
--- gcc/testsuite/gfortran.dg/nullify_2.f90	(revision 184439)
+++ gcc/testsuite/gfortran.dg/nullify_2.f90	(working copy)
@@ -3,5 +3,5 @@ 
 program i
    implicit none
    TYPE (a) t1     ! { dg-error "is being used before" }
-   nullify(t1%x)   ! { dg-error "error in NULLIFY" }
+   nullify(t1%x)   ! { dg-error "Symbol 't1' at .1. has no IMPLICIT type" }
 end program
Index: gcc/testsuite/gfortran.dg/nullify_4.f90
===================================================================
--- gcc/testsuite/gfortran.dg/nullify_4.f90	(revision 184439)
+++ gcc/testsuite/gfortran.dg/nullify_4.f90	(working copy)
@@ -4,5 +4,5 @@ 
 ! Check error recovery; was crashing before.
 !
 real, pointer :: ptr
-nullify(ptr, mesh%coarser) ! { dg-error "Syntax error in NULLIFY statement" }
+nullify(ptr, mesh%coarser) ! { dg-error "Symbol 'mesh' at .1. has no IMPLICIT type" }
 end
Index: gcc/testsuite/gfortran.dg/pointer_init_6.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pointer_init_6.f90	(revision 184439)
+++ gcc/testsuite/gfortran.dg/pointer_init_6.f90	(working copy)
@@ -27,7 +27,7 @@  module m2
  type(t) :: x
  procedure(s), pointer :: pp1 => s
  procedure(s), pointer :: pp2 => pp1    ! { dg-error "may not be a procedure pointer" }
- procedure(s), pointer :: pp3 => t%ppc  ! { dg-error "Syntax error" }
+ procedure(s), pointer :: pp3 => t%ppc  ! { dg-error "Symbol 't' at .1. has no IMPLICIT type" }
 
 contains