diff --git a/gcc/fortran/primary.c b/gcc/fortran/primary.c index d0610d02ebd..7633e77909f 100644 --- a/gcc/fortran/primary.c +++ b/gcc/fortran/primary.c @@ -2407,11 +2407,15 @@ gfc_match_varspec (gfc_expr *primary, int equiv_flag, bool sub_flag, component = NULL; if (intrinsic && !inquiry) - { - gfc_error ("%qs at %C is not an inquiry reference to an intrinsic " - "type component %qs", name, previous->name); + { + if (previous) + gfc_error ("%qs at %C is not an inquiry reference to an intrinsic " + "type component %qs", name, previous->name); + else + gfc_error ("%qs at %C is not an inquiry reference to an intrinsic " + "type component", name); return MATCH_ERROR; - } + } else if (component == NULL && !inquiry) return MATCH_ERROR; diff --git a/gcc/testsuite/gfortran.dg/pr99060.f90 b/gcc/testsuite/gfortran.dg/pr99060.f90 new file mode 100644 index 00000000000..fdf3b1a724e --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr99060.f90 @@ -0,0 +1,10 @@ +! { dg-do compile } +! +! Test the fix for PR99060 in which the expression caused an ICE after the error. +! +! Contributed by Gerhard Steinmetz +! +program p + real :: a + print *, a%kind%n ! { dg-error "not an inquiry reference" } +end