public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Paul Richard Thomas <paul.richard.thomas@gmail.com>
To: "fortran@gcc.gnu.org" <fortran@gcc.gnu.org>,
	gcc-patches <gcc-patches@gcc.gnu.org>
Subject: [Patch, fortran] PR68534 - No error on mismatch in number of arguments between submodule and module interface
Date: Sat, 28 Nov 2015 10:51:00 -0000	[thread overview]
Message-ID: <CAGkQGiJOT-0-PuPJa+Sk_Wm61MT1hrjNpP=tBztpy1KBV2yO=g@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 642 bytes --]

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  <pault@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  <pault@gcc.gnu.org>

    PR fortran/68534
    * gfortran.dg/submodule_13.f08: New test.

[-- Attachment #2: submit.diff --]
[-- Type: text/plain, Size: 2861 bytes --]

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

             reply	other threads:[~2015-11-28 10:35 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-28 10:51 Paul Richard Thomas [this message]
2015-11-28 16:29 ` Steve Kargl
2015-11-30 13:38   ` Paul Richard Thomas
2015-12-03  6:02     ` Steve Kargl
2015-12-03  6:26       ` Steve Kargl
2015-12-03  6:43         ` Steve Kargl
2015-12-03 11:31           ` Paul Richard Thomas
     [not found]           ` <CAGkQGiLhWmeCGXnGn_2_h8tWNQREq6Mt=F4Dc5SqJdoHA0pppw@mail.gmail.com>
     [not found]             ` <20151205164137.GA20634@troutmask.apl.washington.edu>
2015-12-05 17:25               ` Paul Richard Thomas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAGkQGiJOT-0-PuPJa+Sk_Wm61MT1hrjNpP=tBztpy1KBV2yO=g@mail.gmail.com' \
    --to=paul.richard.thomas@gmail.com \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).