gcc/fortran/ChangeLog:
PR fortran/95710
* class.cc (gfc_build_class_symbol): Do not try to build class
container for invalid typespec.
* resolve.cc (resolve_fl_var_and_proc): Prevent NULL pointer
dereference.
(resolve_symbol): Likewise.
gcc/testsuite/ChangeLog:
PR fortran/95710
* gfortran.dg/pr95710.f90: New test.
gcc_assert (as);
+ /* We cannot build the class container now. */
+ if (attr->class_ok && (!ts->u.derived || !ts->u.derived->components))
+ return false;
+
/* Class container has already been built with same name. */
if (attr->class_ok
&& ts->u.derived->components->attr.dimension >= attr->dimension
&& sym->ts.u.derived
&& !sym->attr.select_type_temporary
&& !UNLIMITED_POLY (sym)
+ && CLASS_DATA (sym)
&& CLASS_DATA (sym)->ts.u.derived
&& !gfc_type_is_extensible (CLASS_DATA (sym)->ts.u.derived))
{
specification_expr = saved_specification_expr;
}
- if (sym->ts.type == BT_CLASS && sym->attr.class_ok && sym->ts.u.derived)
+ if (sym->ts.type == BT_CLASS && sym->attr.class_ok && sym->ts.u.derived
+ && CLASS_DATA (sym))
{
as = CLASS_DATA (sym)->as;
class_attr = CLASS_DATA (sym)->attr;
--- /dev/null
+! { dg-do compile }
+! PR fortran/95710 - ICE on duplicate declaration of class variable
+! Contributed by G.Steinmetz
+
+module m
+ interface
+ module function s()
+ end
+ end interface
+end
+submodule(m) m2
+contains
+ module function s()
+ class(*), allocatable :: x
+ class(*), allocatable :: x ! { dg-error "Unclassifiable statement" }
+ end
+end