public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/53956] New: Proc-pointer w/ interface: Bogus "EXTERNAL attribute conflicts with FUNCTION attribute"
@ 2012-07-13 18:26 burnus at gcc dot gnu.org
  2012-07-13 18:57 ` [Bug fortran/53956] " janus at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-07-13 18:26 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53956

             Bug #: 53956
           Summary: Proc-pointer w/ interface: Bogus "EXTERNAL attribute
                    conflicts with FUNCTION attribute"
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: burnus@gcc.gnu.org
                CC: janus@gcc.gnu.org


Found at comp.lang.fortran,
cf. http://www.rhinocerus.net/forum/lang-fortran/709699-sort-2d-matrix-2.html
or
https://groups.google.com/forum/?fromgroups#!topic/comp.lang.fortran/kfOR7y1bI0Q

The original example has been written by James Van Buskirk - see thread.

The following program gives the bogus error when the procedure pointer is
invoked. Without procedure pointer or - for the dummy argument - using
"procedure(integer)" instead of "integer, external" (which is semantically
identically), works.

program testme
              1   
Error: EXTERNAL attribute conflicts with FUNCTION attribute in 'comparator2' at
(1)


module m
contains
  function compare()
    integer :: compare
    compare = 42
  end function compare
  subroutine print_it(x)
    procedure(integer) :: x
    print *, x()
  end subroutine print_it
end module m

program testme
  use m
  implicit none
  interface
    subroutine sub(comparator2)        ! <<< related to those
      integer, external :: comparator2 ! <<< lines
    end subroutine sub
  end interface
  procedure(sub), pointer :: fp  ! << but the interface might be involved
  fp => print_it
  call fp (compare)   ! <<< Triggers the error
end program testme


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug fortran/53956] Proc-pointer w/ interface: Bogus "EXTERNAL attribute conflicts with FUNCTION attribute"
  2012-07-13 18:26 [Bug fortran/53956] New: Proc-pointer w/ interface: Bogus "EXTERNAL attribute conflicts with FUNCTION attribute" burnus at gcc dot gnu.org
@ 2012-07-13 18:57 ` janus at gcc dot gnu.org
  2012-07-13 20:50 ` janus at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: janus at gcc dot gnu.org @ 2012-07-13 18:57 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53956

--- Comment #1 from janus at gcc dot gnu.org 2012-07-13 18:57:44 UTC ---
Reduced test case:

  interface
    subroutine sub (c2)       
      integer, external :: c2 
    end subroutine
  end interface

  procedure(sub) :: fp

end


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug fortran/53956] Proc-pointer w/ interface: Bogus "EXTERNAL attribute conflicts with FUNCTION attribute"
  2012-07-13 18:26 [Bug fortran/53956] New: Proc-pointer w/ interface: Bogus "EXTERNAL attribute conflicts with FUNCTION attribute" burnus at gcc dot gnu.org
  2012-07-13 18:57 ` [Bug fortran/53956] " janus at gcc dot gnu.org
@ 2012-07-13 20:50 ` janus at gcc dot gnu.org
  2012-07-14 13:01 ` janus at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: janus at gcc dot gnu.org @ 2012-07-13 20:50 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53956

janus at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2012-07-13
         AssignedTo|unassigned at gcc dot       |janus at gcc dot gnu.org
                   |gnu.org                     |
     Ever Confirmed|0                           |1

--- Comment #2 from janus at gcc dot gnu.org 2012-07-13 20:49:50 UTC ---
The error itself should be quite easy to fix. Here is a draft patch (not
regtested yet):


Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c    (revision 189470)
+++ gcc/fortran/resolve.c    (working copy)
@@ -10843,7 +10843,8 @@ resolve_fl_procedure (gfc_symbol *sym, int mp_flag
       return FAILURE;
     }
       if (sym->attr.external && sym->attr.function
-      && ((sym->attr.if_source == IFSRC_DECL && !sym->attr.procedure)
+      && ((sym->attr.if_source == IFSRC_DECL && !sym->attr.procedure
+           && !sym->attr.dummy)
           || sym->attr.contained))
     {
       gfc_error ("EXTERNAL attribute conflicts with FUNCTION attribute "



However, there seems to be an additional problem with the locus. Plus, I'm not
sure why the error only occurs with the PROCEDURE statement.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug fortran/53956] Proc-pointer w/ interface: Bogus "EXTERNAL attribute conflicts with FUNCTION attribute"
  2012-07-13 18:26 [Bug fortran/53956] New: Proc-pointer w/ interface: Bogus "EXTERNAL attribute conflicts with FUNCTION attribute" burnus at gcc dot gnu.org
  2012-07-13 18:57 ` [Bug fortran/53956] " janus at gcc dot gnu.org
  2012-07-13 20:50 ` janus at gcc dot gnu.org
@ 2012-07-14 13:01 ` janus at gcc dot gnu.org
  2012-07-16  8:46 ` [Bug fortran/53956] [F03] PROCEDURE " janus at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: janus at gcc dot gnu.org @ 2012-07-14 13:01 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53956

--- Comment #3 from janus at gcc dot gnu.org 2012-07-14 13:01:22 UTC ---
(In reply to comment #2)
> Plus, I'm not
> sure why the error only occurs with the PROCEDURE statement.

Regarding the test case in comment #1, the difference between the c2-args of
'sub' and 'fp' is that the former has IFSRC_UNKNOWN, while the latter has
IFSRC_DECL.

The latter symbol is created by 'gfc_copy_formal_args', and therefore an
alternative (and probably preferable) patch would be:


Index: gcc/fortran/symbol.c
===================================================================
--- gcc/fortran/symbol.c    (revision 189470)
+++ gcc/fortran/symbol.c    (working copy)
@@ -4110,7 +4110,7 @@ gfc_copy_formal_args (gfc_symbol *dest, gfc_symbol
     }

   /* Add the interface to the symbol.  */
-  add_proc_interface (dest, IFSRC_DECL, head);
+  add_proc_interface (dest, src->attr.if_source, head);

   /* Store the formal namespace information.  */
   if (dest->formal != NULL)



> However, there seems to be an additional problem with the locus. 

... which is not a real problem, I guess (since the error message is fake
anyway).


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug fortran/53956] [F03] PROCEDURE w/ interface: Bogus "EXTERNAL attribute conflicts with FUNCTION attribute"
  2012-07-13 18:26 [Bug fortran/53956] New: Proc-pointer w/ interface: Bogus "EXTERNAL attribute conflicts with FUNCTION attribute" burnus at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2012-07-14 13:01 ` janus at gcc dot gnu.org
@ 2012-07-16  8:46 ` janus at gcc dot gnu.org
  2012-07-16 10:13 ` janus at gcc dot gnu.org
  2012-07-16 10:17 ` janus at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: janus at gcc dot gnu.org @ 2012-07-16  8:46 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53956

--- Comment #4 from janus at gcc dot gnu.org 2012-07-16 08:45:56 UTC ---
(In reply to comment #3)
> ... and therefore an
> alternative (and probably preferable) patch would be:

The patch in comment #3 generates the correct if_source for "c2", but a wrong
one for "fp": Since it is just copied from "sub" it becomes IFSRC_IFBODY, but
it should be IFSRC_DECL.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug fortran/53956] [F03] PROCEDURE w/ interface: Bogus "EXTERNAL attribute conflicts with FUNCTION attribute"
  2012-07-13 18:26 [Bug fortran/53956] New: Proc-pointer w/ interface: Bogus "EXTERNAL attribute conflicts with FUNCTION attribute" burnus at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2012-07-16  8:46 ` [Bug fortran/53956] [F03] PROCEDURE " janus at gcc dot gnu.org
@ 2012-07-16 10:13 ` janus at gcc dot gnu.org
  2012-07-16 10:17 ` janus at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: janus at gcc dot gnu.org @ 2012-07-16 10:13 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53956

--- Comment #5 from janus at gcc dot gnu.org 2012-07-16 10:13:26 UTC ---
Author: janus
Date: Mon Jul 16 10:13:19 2012
New Revision: 189514

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=189514
Log:
2012-07-16  Janus Weil  <janus@gcc.gnu.org>

    PR fortran/53956
    * gfortran.h (gfc_copy_formal_args,gfc_copy_formal_args_ppc): Modified
    prototypes.
    * symbol.c (gfc_copy_formal_args): New argument 'if_src'. Copy if_source
    of dummy procedures.
    (gfc_copy_formal_args_ppc): Ditto.
    * resolve.c (resolve_procedure_interface): Pass IFSRC_DECL to
    gfc_copy_formal_args.
    (resolve_fl_derived0): Pass IFSRC_DECL to gfc_copy_formal_args_ppc.


2012-07-16  Janus Weil  <janus@gcc.gnu.org>

    PR fortran/53956
    * gfortran.dg/proc_decl_28.f90: New.

Added:
    trunk/gcc/testsuite/gfortran.dg/proc_decl_28.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/resolve.c
    trunk/gcc/fortran/symbol.c
    trunk/gcc/testsuite/ChangeLog


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug fortran/53956] [F03] PROCEDURE w/ interface: Bogus "EXTERNAL attribute conflicts with FUNCTION attribute"
  2012-07-13 18:26 [Bug fortran/53956] New: Proc-pointer w/ interface: Bogus "EXTERNAL attribute conflicts with FUNCTION attribute" burnus at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2012-07-16 10:13 ` janus at gcc dot gnu.org
@ 2012-07-16 10:17 ` janus at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: janus at gcc dot gnu.org @ 2012-07-16 10:17 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53956

janus at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED

--- Comment #6 from janus at gcc dot gnu.org 2012-07-16 10:17:37 UTC ---
Fixed with r189514. Closing.


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2012-07-16 10:17 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-13 18:26 [Bug fortran/53956] New: Proc-pointer w/ interface: Bogus "EXTERNAL attribute conflicts with FUNCTION attribute" burnus at gcc dot gnu.org
2012-07-13 18:57 ` [Bug fortran/53956] " janus at gcc dot gnu.org
2012-07-13 20:50 ` janus at gcc dot gnu.org
2012-07-14 13:01 ` janus at gcc dot gnu.org
2012-07-16  8:46 ` [Bug fortran/53956] [F03] PROCEDURE " janus at gcc dot gnu.org
2012-07-16 10:13 ` janus at gcc dot gnu.org
2012-07-16 10:17 ` janus at gcc dot gnu.org

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).