Dear All, The check that the number of formal arguments in the submodule procedure declaration is the same as that in the module interface was not working when there were none in either of them. This rather trivial patch remedies the problem.
Bootstrapped and regtested on FC21/x86_64 - OK for trunk? Paul 2015-11-28 Paul Thomas <pa...@gcc.gnu.org> PR fortran/68534 * decl.c (gfc_match_formal_arglist): Cope with zero formal args either in interface declaration or in procedure declaration in submodule. 2015-11-28 Paul Thomas <pa...@gcc.gnu.org> PR fortran/68534 * gfortran.dg/submodule_13.f08: New test.
Index: gcc/fortran/decl.c =================================================================== *** gcc/fortran/decl.c (revision 230783) --- gcc/fortran/decl.c (working copy) *************** ok: *** 4817,4830 **** goto cleanup; } ! if (formal) { for (p = formal, q = head; p && q; p = p->next, q = q->next) { if ((p->next != NULL && q->next == NULL) || (p->next == NULL && q->next != NULL)) ! gfc_error_now ("Mismatch in number of MODULE PROCEDURE " ! "formal arguments at %C"); else if ((p->sym == NULL && q->sym == NULL) || strcmp (p->sym->name, q->sym->name) == 0) continue; --- 4817,4839 ---- goto cleanup; } ! if (progname->attr.module_procedure && progname->attr.host_assoc) { + bool arg_count_mismatch = false; + + if (!formal && head) + arg_count_mismatch = true; + + /* Abreviated module procedure declaration is not meant to have any + formal arguments! */ + if (!sym->abr_modproc_decl && formal && !head) + arg_count_mismatch = true; + for (p = formal, q = head; p && q; p = p->next, q = q->next) { if ((p->next != NULL && q->next == NULL) || (p->next == NULL && q->next != NULL)) ! arg_count_mismatch = true; else if ((p->sym == NULL && q->sym == NULL) || strcmp (p->sym->name, q->sym->name) == 0) continue; *************** ok: *** 4833,4838 **** --- 4842,4851 ---- "argument names (%s/%s) at %C", p->sym->name, q->sym->name); } + + if (arg_count_mismatch) + gfc_error_now ("Mismatch in number of MODULE PROCEDURE " + "formal arguments at %C"); } return MATCH_YES; Index: gcc/testsuite/gfortran.dg/submodule_13.f08 =================================================================== *** gcc/testsuite/gfortran.dg/submodule_13.f08 (revision 0) --- gcc/testsuite/gfortran.dg/submodule_13.f08 (working copy) *************** *** 0 **** --- 1,32 ---- + ! { dg-do compile } + ! + ! Checks the fix for PR68534 in which checks for the number + ! failed if either the interface or the module procedure had + ! no dummies. + ! + ! Reported on clf at: + ! https://groups.google.com/forum/#!topic/comp.lang.fortran/-ZgbM5qkFmc + ! + module m + implicit none + interface + module subroutine foo() + end subroutine foo + + module subroutine bar(i) + integer, intent(inout) :: i + end subroutine bar + end interface + end module m + + submodule(m) sm + contains + module subroutine foo(i) ! { dg-error "Mismatch in number of MODULE PROCEDURE formal" } + integer, intent(inout) :: i + i = 42 + end subroutine foo + + module subroutine bar ! { dg-error "Mismatch in number of MODULE PROCEDURE formal" } + print *, "bar" + end subroutine bar + end submodule sm