Index: gcc/fortran/primary.c =================================================================== *** gcc/fortran/primary.c (révision 116697) --- gcc/fortran/primary.c (copie de travail) *************** match_variable (gfc_expr ** result, int *** 2282,2287 **** --- 2285,2301 ---- gfc_expr *expr; locus where; match m; + + /* Since nothing has any business being an lvalue in a module + specification block, an interface block or a contains section, + we force the changed_symbols mechanism to work by setting + host_flag to 0. This prevents valid symbols that have the name + of keywords, such as 'end', being turned into variables by + failed matching to assignments for, eg., END INTERFACE. */ + if (gfc_current_state () == COMP_MODULE + || gfc_current_state () == COMP_INTERFACE + || gfc_current_state () == COMP_CONTAINS) + host_flag = 0; m = gfc_match_sym_tree (&st, host_flag); if (m != MATCH_YES) Index: gcc/testsuite/gfortran.dg/keyword_symbol_1.f90 =================================================================== *** gcc/testsuite/gfortran.dg/keyword_symbol_1.f90 (révision 0) --- gcc/testsuite/gfortran.dg/keyword_symbol_1.f90 (révision 0) *************** *** 0 **** --- 1,57 ---- + ! ' dg-do compile } + ! This tests the fix for PR28526, in which a public interface named + ! 'end' would be treated as a variable because the matcher tried + ! 'END INTERFACE' as an assignment and left the symbol modified in + ! failing. The various pitfalls that were encountered in developing + ! the fix are checked here. + ! + ! Contributed by Paul Thomas + ! + module blahblah + public function, end + + ! The original PR from Yusuke IGUCHI + interface end + module procedure foo1 + end interface + + ! A contribution to the PR from Tobias Schlueter + interface function + module procedure foo2 ! { dg-error "is neither function nor" } + end interface + + interface function + module procedure foo3 + end interface + + interface + function foo4 () + real foo4 + x = 1.0 ! { dg-error "in MODULE" } + end function foo4 + end interface + + interface + x = 2.0 ! { dg-error "in INTERFACE block" } + function foo5 () + real foo5 + end function foo5 + end interface + + x = 3.0 ! { dg-error "in MODULE" } + + contains + + subroutine foo1 + end subroutine foo1 + + function foo2 ! { dg-error "Expected formal argument list" } + foo2 = 0 ! { dg-error "already been host associated" } + end function foo2 ! { dg-error "Expecting END MODULE" } + + function foo3 () + real foo3 + end function foo3 + + x = 4.0 ! { dg-error "in CONTAINS section" } + end module blahblah