public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/53694] New: [OOP] GENERIC type-bound procs should be available without part-ref syntax
@ 2012-06-16  8:45 burnus at gcc dot gnu.org
  2012-06-17  8:52 ` [Bug fortran/53694] " janus at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-06-16  8:45 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 53694
           Summary: [OOP] GENERIC type-bound procs should be available
                    without part-ref syntax
    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


Created attachment 27629
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27629
test.f90

If "sqrt" is a generic type-bound procedure, not only something like
  a%sqrt()  or  a%sqrt(b)   [for pass and nopass, respectively]
should work but also a simple:
  sqrt(a)   or  sqrt(a, b)

That is: The generic enter the normal generic namespace with the exception that
  use, only: type
also imports the generic name for that type.

See also: https://groups.google.com/forum/#!msg/comp.lang.fortran/YDt3j0--1Do


It is not obvious from the standard that this holds, but it is analog to
ASSIGNMENT(=) and OPERATOR(...) which also act that way. [Which is supported in
gfortran.]  Additionally, the following statement (F2008,4.5.7.3 Type-bound
procedure overriding) wouldn't make sense with a different interpretation of
the standard:

"If a generic binding speci\fed in a type de\fnition has the same generic-spec as
an inherited binding, it extends the generic interface and shall satisfy the
requirements speci\fed in 12.4.3.4.5."


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

* [Bug fortran/53694] [OOP] GENERIC type-bound procs should be available without part-ref syntax
  2012-06-16  8:45 [Bug fortran/53694] New: [OOP] GENERIC type-bound procs should be available without part-ref syntax burnus at gcc dot gnu.org
@ 2012-06-17  8:52 ` janus at gcc dot gnu.org
  2012-06-17 17:20 ` janus at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: janus at gcc dot gnu.org @ 2012-06-17  8:52 UTC (permalink / raw)
  To: gcc-bugs

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

janus at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |janus at gcc dot gnu.org

--- Comment #1 from janus at gcc dot gnu.org 2012-06-17 08:52:44 UTC ---
(In reply to comment #0)
> See also: https://groups.google.com/forum/#!msg/comp.lang.fortran/YDt3j0--1Do

Note: That link does not seem to work.


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

* [Bug fortran/53694] [OOP] GENERIC type-bound procs should be available without part-ref syntax
  2012-06-16  8:45 [Bug fortran/53694] New: [OOP] GENERIC type-bound procs should be available without part-ref syntax burnus at gcc dot gnu.org
  2012-06-17  8:52 ` [Bug fortran/53694] " janus at gcc dot gnu.org
@ 2012-06-17 17:20 ` janus at gcc dot gnu.org
  2012-06-17 19:07 ` burnus at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: janus at gcc dot gnu.org @ 2012-06-17 17:20 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from janus at gcc dot gnu.org 2012-06-17 17:19:57 UTC ---
(In reply to comment #0)
> It is not obvious from the standard that this holds, but it is analog to
> ASSIGNMENT(=) and OPERATOR(...) which also act that way. [Which is supported in
> gfortran.]

It is correct that gfortran supports this for ASSIGNMENTs and OPERATORs.
However, there are problems, cf. PR 41951 comment 6 to 10.

The two PRs might be fixable in one go.


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

* [Bug fortran/53694] [OOP] GENERIC type-bound procs should be available without part-ref syntax
  2012-06-16  8:45 [Bug fortran/53694] New: [OOP] GENERIC type-bound procs should be available without part-ref syntax burnus at gcc dot gnu.org
  2012-06-17  8:52 ` [Bug fortran/53694] " janus at gcc dot gnu.org
  2012-06-17 17:20 ` janus at gcc dot gnu.org
@ 2012-06-17 19:07 ` burnus at gcc dot gnu.org
  2012-06-17 22:03 ` janus at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-06-17 19:07 UTC (permalink / raw)
  To: gcc-bugs

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

Tobias Burnus <burnus at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |burnus at gcc dot gnu.org

--- Comment #3 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-06-17 19:06:58 UTC ---
(In reply to comment #1)
> (In reply to comment #0)
> > See also: https://groups.google.com/forum/#!msg/comp.lang.fortran/YDt3j0--1Do
> Note: That link does not seem to work.

Try:

http://www.rhinocerus.net/forum/lang-fortran/708232-there-way-do-following.html


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

* [Bug fortran/53694] [OOP] GENERIC type-bound procs should be available without part-ref syntax
  2012-06-16  8:45 [Bug fortran/53694] New: [OOP] GENERIC type-bound procs should be available without part-ref syntax burnus at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2012-06-17 19:07 ` burnus at gcc dot gnu.org
@ 2012-06-17 22:03 ` janus at gcc dot gnu.org
  2012-06-19  9:53 ` janus at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: janus at gcc dot gnu.org @ 2012-06-17 22:03 UTC (permalink / raw)
  To: gcc-bugs

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

janus at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-06-17
     Ever Confirmed|0                           |1

--- Comment #4 from janus at gcc dot gnu.org 2012-06-17 22:03:05 UTC ---
Slightly compactified test case:


module type_mod
  implicit none

  type field
     real :: var(1:3)
   contains
     procedure :: scalar_equals_field
     generic :: assignment (=) => scalar_equals_field
     procedure, nopass :: field_sqrt
     generic :: sqrt => field_sqrt
  end type

contains

  elemental pure subroutine scalar_equals_field (A, b)
    class(field), intent(out) :: A
    real, intent(in) :: b
    A%var(:) = b
  end subroutine

  elemental pure function field_sqrt (A) result (B)
    class(field), intent(in) :: A
    type(field) :: B
    B%var(:) = sqrt (A%var(:))
  end function

end module


program test
  use type_mod, only : field
  implicit none
  type(field) :: a

  a = 4.0
  print *, sqrt(a)

end program


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

* [Bug fortran/53694] [OOP] GENERIC type-bound procs should be available without part-ref syntax
  2012-06-16  8:45 [Bug fortran/53694] New: [OOP] GENERIC type-bound procs should be available without part-ref syntax burnus at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2012-06-17 22:03 ` janus at gcc dot gnu.org
@ 2012-06-19  9:53 ` janus at gcc dot gnu.org
  2012-06-19 10:47 ` janus at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: janus at gcc dot gnu.org @ 2012-06-19  9:53 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from janus at gcc dot gnu.org 2012-06-19 09:52:42 UTC ---
(In reply to comment #3)
> > > See also: https://groups.google.com/forum/#!msg/comp.lang.fortran/YDt3j0--1Do
> > Note: That link does not seem to work.
> 
> Try:
> 
> http://www.rhinocerus.net/forum/lang-fortran/708232-there-way-do-following.html

The correct google groups link would be:

https://groups.google.com/forum/#!topic/comp.lang.fortran/YDt3j0--1Do


Btw, I'm not completely convinced yet that the code in comment #0 (and #4) is
really legal. No one in the c.l.f. thread has brought up a quote from the
standard which clearly shows that referencing a type-bound generic is legal
without part-ref syntax.


For me, to most convincing reference up to now is this quote from
F08:12.4.3.4.5 (though it still sounds a bit 'cloudy' to me):

NOTE 12.10
In most scoping units, the possible sources of procedures with a particular
generic identifier are the accessible interface blocks and the generic bindings
other than names for the accessible objects in that scoping unit.


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

* [Bug fortran/53694] [OOP] GENERIC type-bound procs should be available without part-ref syntax
  2012-06-16  8:45 [Bug fortran/53694] New: [OOP] GENERIC type-bound procs should be available without part-ref syntax burnus at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2012-06-19  9:53 ` janus at gcc dot gnu.org
@ 2012-06-19 10:47 ` janus at gcc dot gnu.org
  2012-06-19 21:56 ` janus at gcc dot gnu.org
  2012-06-21 14:39 ` burnus at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: janus at gcc dot gnu.org @ 2012-06-19 10:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from janus at gcc dot gnu.org 2012-06-19 10:46:56 UTC ---
(In reply to comment #5)
> Btw, I'm not completely convinced yet that the code in comment #0 (and #4) is
> really legal.

In any case, here is a simple draft patch, which makes the code in comment 4
work (at least when the ONLY clause in the USE statement is removed):


Index: gcc/fortran/decl.c
===================================================================
--- gcc/fortran/decl.c    (revision 188334)
+++ gcc/fortran/decl.c    (working copy)
@@ -8374,12 +8374,20 @@ gfc_match_generic (void)
       {
         const bool is_op = (op_type == INTERFACE_USER_OP);
         gfc_symtree* st;
+        gfc_symbol *gensym;

         st = gfc_new_symtree (is_op ? &ns->tb_uop_root : &ns->tb_sym_root,
                   name);
         gcc_assert (st);
         st->n.tb = tb;

+        /* Create non-typebound generic symbol.  */
+        if (gfc_get_symbol (name, NULL, &gensym))
+          return MATCH_ERROR;
+        if (!gensym->attr.generic
+        && gfc_add_generic (&gensym->attr, gensym->name, NULL) == FAILURE)
+          return MATCH_ERROR;
+        
         break;
       }

Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c    (revision 188335)
+++ gcc/fortran/resolve.c    (working copy)
@@ -11125,6 +11125,26 @@ specific_found:
         return FAILURE;
       }

+    /* Add target to (non-typebound) generic symbol.  */
+    if (!p->u.generic->is_operator)
+      {
+        gfc_symbol *gensym;
+        if (gfc_get_symbol (name, NULL, &gensym))
+          return FAILURE;
+        if (gensym)
+          {
+        gfc_interface *head, *intr;
+        head = gensym->generic;
+        intr = gfc_get_interface ();
+        intr->sym = target->specific->u.specific->n.sym;
+        intr->where = gfc_current_locus;
+        intr->sym->declared_at = gfc_current_locus;
+        intr->next = head;
+        gensym->generic = intr;
+        gfc_commit_symbol (gensym);
+          }
+      }
+
     /* Check those already resolved on this type directly.  */
     for (g = p->u.generic; g; g = g->next)
       if (g != target && g->specific


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

* [Bug fortran/53694] [OOP] GENERIC type-bound procs should be available without part-ref syntax
  2012-06-16  8:45 [Bug fortran/53694] New: [OOP] GENERIC type-bound procs should be available without part-ref syntax burnus at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2012-06-19 10:47 ` janus at gcc dot gnu.org
@ 2012-06-19 21:56 ` janus at gcc dot gnu.org
  2012-06-21 14:39 ` burnus at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: janus at gcc dot gnu.org @ 2012-06-19 21:56 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from janus at gcc dot gnu.org 2012-06-19 21:56:09 UTC ---
One problem with the patch in comment #6 is that it produces double error
messages for type-bound generics, e.g. on typebound_generic_{1,10,11}.


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

* [Bug fortran/53694] [OOP] GENERIC type-bound procs should be available without part-ref syntax
  2012-06-16  8:45 [Bug fortran/53694] New: [OOP] GENERIC type-bound procs should be available without part-ref syntax burnus at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2012-06-19 21:56 ` janus at gcc dot gnu.org
@ 2012-06-21 14:39 ` burnus at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-06-21 14:39 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-06-21 14:39:32 UTC ---
Actually, I am no longer sure that this PR is valid - nor is Richard Maine in
c.l.f. Janus seems to have the same doubts, if I read comment 5 correctly.

The standard seems to make a distinction between 'generic type-bound procedure'
and 'generic procedure name'.


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

end of thread, other threads:[~2012-06-21 14:39 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-16  8:45 [Bug fortran/53694] New: [OOP] GENERIC type-bound procs should be available without part-ref syntax burnus at gcc dot gnu.org
2012-06-17  8:52 ` [Bug fortran/53694] " janus at gcc dot gnu.org
2012-06-17 17:20 ` janus at gcc dot gnu.org
2012-06-17 19:07 ` burnus at gcc dot gnu.org
2012-06-17 22:03 ` janus at gcc dot gnu.org
2012-06-19  9:53 ` janus at gcc dot gnu.org
2012-06-19 10:47 ` janus at gcc dot gnu.org
2012-06-19 21:56 ` janus at gcc dot gnu.org
2012-06-21 14:39 ` burnus 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).