From 976e21f67321ad483895471c5f285a1880a47b4a Mon Sep 17 00:00:00 2001 From: Paul Thomas Date: Wed, 26 Oct 2005 05:20:19 +0000 Subject: re PR fortran/24158 (ICE in f951 with nested, recursive derived types) 2005-10-26 Paul Thomas PR fortran/24158 * decl.c (gfc_match_data_decl): Correct broken bit of code that prevents undefined derived types from being used as components of another derived type. * resolve.c (resolve_symbol): Add backstop error when derived type variables arrive here with a type that has no components. 2005-10-26 Paul Thomas PR fortran/24158 gfortran.dg/derived_recursion.f90: New test. gfortran.dg/implicit_actual.f90: New test. From-SVN: r105913 --- gcc/fortran/ChangeLog | 9 +++++++++ gcc/fortran/decl.c | 20 ++++++++++++-------- gcc/fortran/resolve.c | 18 ++++++++++++++++++ 3 files changed, 39 insertions(+), 8 deletions(-) (limited to 'gcc/fortran') diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 233f149..2cfea31 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,12 @@ +2005-10-26 Paul Thomas + + PR fortran/24158 + * decl.c (gfc_match_data_decl): Correct broken bit of code + that prevents undefined derived types from being used as + components of another derived type. + * resolve.c (resolve_symbol): Add backstop error when derived + type variables arrive here with a type that has no components. + 2005-10-25 Jakub Jelinek * trans.h (gfc_conv_cray_pointee): Remove. diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c index 5d4bd56..8c2895ed 100644 --- a/gcc/fortran/decl.c +++ b/gcc/fortran/decl.c @@ -2075,17 +2075,21 @@ gfc_match_data_decl (void) if (current_attr.pointer && gfc_current_state () == COMP_DERIVED) goto ok; - if (gfc_find_symbol (current_ts.derived->name, - current_ts.derived->ns->parent, 1, &sym) == 0) - goto ok; + gfc_find_symbol (current_ts.derived->name, + current_ts.derived->ns->parent, 1, &sym); - /* Hope that an ambiguous symbol is itself masked by a type definition. */ - if (sym != NULL && sym->attr.flavor == FL_DERIVED) + /* Any symbol that we find had better be a type definition + which has its components defined. */ + if (sym != NULL && sym->attr.flavor == FL_DERIVED + && current_ts.derived->components != NULL) goto ok; - gfc_error ("Derived type at %C has not been previously defined"); - m = MATCH_ERROR; - goto cleanup; + /* Now we have an error, which we signal, and then fix up + because the knock-on is plain and simple confusing. */ + gfc_error_now ("Derived type at %C has not been previously defined " + "and so cannot appear in a derived type definition."); + current_attr.pointer = 1; + goto ok; } ok: diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 6c03126..03206bb 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -4339,6 +4339,24 @@ resolve_symbol (gfc_symbol * sym) } } + /* If a derived type symbol has reached this point, without its + type being declared, we have an error. Notice that most + conditions that produce undefined derived types have already + been dealt with. However, the likes of: + implicit type(t) (t) ..... call foo (t) will get us here if + the type is not declared in the scope of the implicit + statement. Change the type to BT_UNKNOWN, both because it is so + and to prevent an ICE. */ + if (sym->ts.type == BT_DERIVED + && sym->ts.derived->components == NULL) + { + gfc_error ("The derived type '%s' at %L is of type '%s', " + "which has not been defined.", sym->name, + &sym->declared_at, sym->ts.derived->name); + sym->ts.type = BT_UNKNOWN; + return; + } + /* Ensure that derived type components of a public derived type are not of a private type. */ if (sym->attr.flavor == FL_DERIVED -- cgit v1.1