https://gcc.gnu.org/g:5e6937b9ab4f752c22b4e2fd0e01836a0df24653
commit r16-4016-g5e6937b9ab4f752c22b4e2fd0e01836a0df24653 Author: Paul Thomas <pa...@gcc.gnu.org> Date: Mon Sep 22 07:33:07 2025 +0100 Fortran: Fix error recovery after missing END BLOCK [PR103508] 2025-09-22 Steve Kargl <pa...@gcc.gnu.org> gcc/fortran PR fortran/103508 * decl.cc (gfc_match_end): Remove only the current partial rather than removing the entire sibling chain. gcc/testsuite/ PR fortran/103508 * gfortran.dg/pr103508.f90: New test. Diff: --- gcc/fortran/decl.cc | 2 +- gcc/testsuite/gfortran.dg/pr103508.f90 | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc index 996449390563..102c6a8e8df8 100644 --- a/gcc/fortran/decl.cc +++ b/gcc/fortran/decl.cc @@ -8986,7 +8986,7 @@ cleanup: /* If we are missing an END BLOCK, we created a half-ready namespace. Remove it from the parent namespace's sibling list. */ - while (state == COMP_BLOCK && !got_matching_end) + if (state == COMP_BLOCK && !got_matching_end) { parent_ns = gfc_current_ns->parent; diff --git a/gcc/testsuite/gfortran.dg/pr103508.f90 b/gcc/testsuite/gfortran.dg/pr103508.f90 new file mode 100644 index 000000000000..541b9b2d1f03 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr103508.f90 @@ -0,0 +1,22 @@ +! { dg-do compile } +! +! Check the fix for PR103508. As noted in comment 6 of the PR, the bug +! has nothing to do with PDTs. However, the contributor's test has been +! retained. +! +! Contributed by Gerhard Steinmetz <gs...@t-online.de> +! +program p + type t + integer :: n = 1 + character(3) :: c + end type + block + block + type(t) :: x + x%c = 'abc' + print *, len(x%c) + end ! { dg-error "END BLOCK statement expected" } + end ! { dg-error "END BLOCK statement expected" } +end +! { dg-error "Unexpected end of file" "" { target "*-*-*" } 0 }