Index: gcc/fortran/parse.c =================================================================== --- gcc/fortran/parse.c (revision 223094) +++ gcc/fortran/parse.c (working copy) @@ -2425,8 +2425,7 @@ verify_st_order (st_state *p, gfc_statem break; default: - gfc_internal_error ("Unexpected %s statement in verify_st_order() at %C", - gfc_ascii_statement (st)); + return false; } /* All is well, record the statement in case we need it next time. */ Index: gcc/testsuite/gfortran.dg/misplaced_statement.f90 =================================================================== --- gcc/testsuite/gfortran.dg/misplaced_statement.f90 (revision 0) +++ gcc/testsuite/gfortran.dg/misplaced_statement.f90 (working copy) @@ -0,0 +1,20 @@ +!{ dg-do compile } +! PR fortran/66040 +! +! Original code from Gerhard Steinmetz +! +real function f1(x) + sequence ! { dg-error "Unexpected SEQUENCE statement" } +end function f1 + +real function f2() + else ! { dg-error "Unexpected ELSE statement" } +end function f2 + +real function f3() + block data ! { dg-error "Unexpected BLOCK DATA statement" } +end function f3 + +real function f4() + program p ! { dg-error "Unexpected PROGRAM statement" } +end function f4