public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/44044]  New: [OOP] SELECT TYPE with class-valued function
@ 2010-05-08 20:08 janus at gcc dot gnu dot org
  2010-05-08 20:14 ` [Bug fortran/44044] " janus at gcc dot gnu dot org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: janus at gcc dot gnu dot org @ 2010-05-08 20:08 UTC (permalink / raw)
  To: gcc-bugs

The following (valid) test case is currently rejected:


implicit none

type :: t1
  integer :: i
end type

type, extends(t1) :: t2
end type

type(t1),target :: x1
type(t2),target :: x2

select type ( y => fun(1) )
type is (t1)
  print *,"t1"
type is (t2)
  print *,"t2"
class default
  print *,"default"
end select

select type ( y => fun(-1) )
type is (t1)
  print *,"t1"
type is (t2)
  print *,"t2"
class default
  print *,"default"
end select

contains

  function fun(i)
    class(t1),pointer :: fun
    integer :: i
    if (i>0) then
      fun => x1
    else if (i<0) then
      fun => x2
    else
      fun => NULL()
    end if
  end function

end


... with the bogus message:

select type ( y => fun(1) )
                           1
Error: Selector shall be polymorphic in SELECT TYPE statement at (1)


-- 
           Summary: [OOP] SELECT TYPE with class-valued function
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: janus at gcc dot gnu dot org


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


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

* [Bug fortran/44044] [OOP] SELECT TYPE with class-valued function
  2010-05-08 20:08 [Bug fortran/44044] New: [OOP] SELECT TYPE with class-valued function janus at gcc dot gnu dot org
@ 2010-05-08 20:14 ` janus at gcc dot gnu dot org
  2010-05-08 20:20 ` janus at gcc dot gnu dot org
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: janus at gcc dot gnu dot org @ 2010-05-08 20:14 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from janus at gcc dot gnu dot org  2010-05-08 20:13 -------
Side note: Invalid code like

  function fun()
    class(t1) :: fun
  end function

is not rejected, although the polymorphic 'fun' is neither a pointer,
allocatable nor a dummy.


-- 


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


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

* [Bug fortran/44044] [OOP] SELECT TYPE with class-valued function
  2010-05-08 20:08 [Bug fortran/44044] New: [OOP] SELECT TYPE with class-valued function janus at gcc dot gnu dot org
  2010-05-08 20:14 ` [Bug fortran/44044] " janus at gcc dot gnu dot org
@ 2010-05-08 20:20 ` janus at gcc dot gnu dot org
  2010-05-08 20:23 ` janus at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: janus at gcc dot gnu dot org @ 2010-05-08 20:20 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from janus at gcc dot gnu dot org  2010-05-08 20:20 -------
Bonus feature #1:

Adding this to comment #0 ...

select type ( y => fun(0) )
type is (t1)
  print *,"t1"
type is (t2)
  print *,"t2"
class default
  print *,"default"
end select

... should give a runtime error, since fun(0) evaluates to NULL.

F08 section 16.5.1.6 demands that, if the selector is a pointer, it should be
associated.

In the same way, having an allocatable selector which is not allocated, should
also give a runtime error.


-- 


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


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

* [Bug fortran/44044] [OOP] SELECT TYPE with class-valued function
  2010-05-08 20:08 [Bug fortran/44044] New: [OOP] SELECT TYPE with class-valued function janus at gcc dot gnu dot org
  2010-05-08 20:14 ` [Bug fortran/44044] " janus at gcc dot gnu dot org
  2010-05-08 20:20 ` janus at gcc dot gnu dot org
@ 2010-05-08 20:23 ` janus at gcc dot gnu dot org
  2010-05-09 11:55 ` janus at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: janus at gcc dot gnu dot org @ 2010-05-08 20:23 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from janus at gcc dot gnu dot org  2010-05-08 20:23 -------
Bonus feature #2:

select type ( y => fun(1) )
type is (t1)
  y%i = 1
type is (t2)
  y%i = 2
end select

... should be rejected, due to (F08):

C836 (R847) If selector is not a variable or is a variable that has a vector
subscript, associate-name shall not appear in a variable de&#64257;nition
context (16.6.7).


-- 


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


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

* [Bug fortran/44044] [OOP] SELECT TYPE with class-valued function
  2010-05-08 20:08 [Bug fortran/44044] New: [OOP] SELECT TYPE with class-valued function janus at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2010-05-08 20:23 ` janus at gcc dot gnu dot org
@ 2010-05-09 11:55 ` janus at gcc dot gnu dot org
  2010-05-10 10:06 ` burnus at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: janus at gcc dot gnu dot org @ 2010-05-09 11:55 UTC (permalink / raw)
  To: gcc-bugs



-- 

janus at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |janus at gcc dot gnu dot org
                   |dot org                     |
             Status|UNCONFIRMED                 |ASSIGNED
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2010-05-09 11:55:17
               date|                            |


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


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

* [Bug fortran/44044] [OOP] SELECT TYPE with class-valued function
  2010-05-08 20:08 [Bug fortran/44044] New: [OOP] SELECT TYPE with class-valued function janus at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2010-05-09 11:55 ` janus at gcc dot gnu dot org
@ 2010-05-10 10:06 ` burnus at gcc dot gnu dot org
  2010-05-10 12:54 ` janus at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: burnus at gcc dot gnu dot org @ 2010-05-10 10:06 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from burnus at gcc dot gnu dot org  2010-05-10 10:05 -------
(In reply to comment #2)
> ... should give a runtime error, since fun(0) evaluates to NULL.
> 
> F08 section 16.5.1.6 demands that, if the selector is a pointer, it should be
> associated.
> In the same way, having an allocatable selector which is not allocated, should
> also give a runtime error.

"If the selector has the POINTER attribute, it shall be associated"
"If the selector is allocatable, it shall be allocated"

Note: Those are not constraints, which the compiler has to diagnose but
constraints to the programmer. The compiler might diagnose those, but I think
it should not do so by default. Similarly to
  ptr = 5
where gfortran also does not do any checking. (Some checks are done for
-fcheck=pointer, though not for this one.) You can add a check using -fcheck=*
but doing a general check I do not like for performance / code-size reasons.


-- 


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


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

* [Bug fortran/44044] [OOP] SELECT TYPE with class-valued function
  2010-05-08 20:08 [Bug fortran/44044] New: [OOP] SELECT TYPE with class-valued function janus at gcc dot gnu dot org
                   ` (4 preceding siblings ...)
  2010-05-10 10:06 ` burnus at gcc dot gnu dot org
@ 2010-05-10 12:54 ` janus at gcc dot gnu dot org
  2010-05-17  8:26 ` janus at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: janus at gcc dot gnu dot org @ 2010-05-10 12:54 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from janus at gcc dot gnu dot org  2010-05-10 12:54 -------
Subject: Bug 44044

Author: janus
Date: Mon May 10 12:54:25 2010
New Revision: 159217

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=159217
Log:
2010-05-10  Janus Weil  <janus@gcc.gnu.org>

        PR fortran/44044
        * match.c (gfc_match_select_type): Move error message to
        resolve_select_type.
        * resolve.c (resolve_select_type): Error message moved here from
        gfc_match_select_type. Correctly set type of temporary.


2010-05-10  Janus Weil  <janus@gcc.gnu.org>

        PR fortran/44044
        * gfortran.dg/class_7.f03: Modified.
        * gfortran.dg/select_type_1.f03: Modified.
        * gfortran.dg/select_type_12.f03: New.

Added:
    trunk/gcc/testsuite/gfortran.dg/select_type_12.f03
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/match.c
    trunk/gcc/fortran/resolve.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/class_7.f03
    trunk/gcc/testsuite/gfortran.dg/select_type_1.f03


-- 


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


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

* [Bug fortran/44044] [OOP] SELECT TYPE with class-valued function
  2010-05-08 20:08 [Bug fortran/44044] New: [OOP] SELECT TYPE with class-valued function janus at gcc dot gnu dot org
                   ` (5 preceding siblings ...)
  2010-05-10 12:54 ` janus at gcc dot gnu dot org
@ 2010-05-17  8:26 ` janus at gcc dot gnu dot org
  2010-05-17  8:32 ` janus at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: janus at gcc dot gnu dot org @ 2010-05-17  8:26 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from janus at gcc dot gnu dot org  2010-05-17 08:25 -------
Subject: Bug 44044

Author: janus
Date: Mon May 17 08:25:06 2010
New Revision: 159476

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=159476
Log:
2010-05-17  Janus Weil  <janus@gcc.gnu.org>

        PR fortran/44044
        * resolve.c (resolve_fl_var_and_proc): Move error messages here from
...
        (resolve_fl_variable_derived): ... this place.
        (resolve_symbol): Make sure function symbols (and their result
        variables) are not resolved twice.


2010-05-17  Janus Weil  <janus@gcc.gnu.org>

        PR fortran/44044
        * gfortran.dg/class_20.f03: New.

Added:
    trunk/gcc/testsuite/gfortran.dg/class_20.f03
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/resolve.c
    trunk/gcc/testsuite/ChangeLog


-- 


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


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

* [Bug fortran/44044] [OOP] SELECT TYPE with class-valued function
  2010-05-08 20:08 [Bug fortran/44044] New: [OOP] SELECT TYPE with class-valued function janus at gcc dot gnu dot org
                   ` (6 preceding siblings ...)
  2010-05-17  8:26 ` janus at gcc dot gnu dot org
@ 2010-05-17  8:32 ` janus at gcc dot gnu dot org
  2010-08-27  7:31 ` burnus at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: janus at gcc dot gnu dot org @ 2010-05-17  8:32 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from janus at gcc dot gnu dot org  2010-05-17 08:31 -------
Comment #0 and #1 are fixed at this point. I think the runtime checking in
comment #2 one can ignore for the moment, since most usage cases of ordinary
pointers are also not checked for.

So the only ToDo item left here is comment #3.


-- 


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


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

* [Bug fortran/44044] [OOP] SELECT TYPE with class-valued function
  2010-05-08 20:08 [Bug fortran/44044] New: [OOP] SELECT TYPE with class-valued function janus at gcc dot gnu dot org
                   ` (7 preceding siblings ...)
  2010-05-17  8:32 ` janus at gcc dot gnu dot org
@ 2010-08-27  7:31 ` burnus at gcc dot gnu dot org
  2010-09-23  8:38 ` domob at gcc dot gnu dot org
  2010-09-23  8:39 ` domob at gcc dot gnu dot org
  10 siblings, 0 replies; 12+ messages in thread
From: burnus at gcc dot gnu dot org @ 2010-08-27  7:31 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from burnus at gcc dot gnu dot org  2010-08-27 07:30 -------
(In reply to comment #7)
> So the only ToDo item left here is comment #3.

Which is C836, i.e. checking invalid use of the selector in a variable
definition context.

This will probably be fixes as part of PR 38936 (ASSOCIATE construct; SELECT
TYPE uses it internally) - thus mark this PR as depending on PR 38936.


-- 

burnus at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  BugsThisDependsOn|                            |38936


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


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

* [Bug fortran/44044] [OOP] SELECT TYPE with class-valued function
  2010-05-08 20:08 [Bug fortran/44044] New: [OOP] SELECT TYPE with class-valued function janus at gcc dot gnu dot org
                   ` (8 preceding siblings ...)
  2010-08-27  7:31 ` burnus at gcc dot gnu dot org
@ 2010-09-23  8:38 ` domob at gcc dot gnu dot org
  2010-09-23  8:39 ` domob at gcc dot gnu dot org
  10 siblings, 0 replies; 12+ messages in thread
From: domob at gcc dot gnu dot org @ 2010-09-23  8:38 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from domob at gcc dot gnu dot org  2010-09-23 08:38 -------
Subject: Bug 44044

Author: domob
Date: Thu Sep 23 08:37:54 2010
New Revision: 164550

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=164550
Log:
2010-09-23  Daniel Kraft  <d@domob.eu>

        PR fortran/38936
        PR fortran/44044
        PR fortran/45474
        * gfortran.h (gfc_check_vardef_context): New method.
        (struct symbol_attribute): New flag `select_type_temporary'.
        * primary.c (gfc_variable_attr): Clarify initialization of ref.
        (match_variable): Remove PROTECTED check and assignment check
        for PARAMETERs (this is now done later).
        * match.c (gfc_match_iterator): Remove INTENT(IN) check.
        (gfc_match_associate): Defer initialization of newAssoc->variable.
        (gfc_match_nullify): Remove PURE definability check.
        (select_type_set_tmp): Set new `select_type_temporary' flag.
        * expr.c (gfc_check_assign): Remove INTENT(IN) check here.
        (gfc_check_pointer_assign): Ditto (and other checks removed).
        (gfc_check_vardef_context): New method.
        * interface.c (compare_parameter_protected): Removed.
        (compare_actual_formal): Use `gfc_check_vardef_context' for checks
        related to INTENT([IN]OUT) arguments.
        * intrinsic.c (check_arglist): Check INTENT for intrinsics.
        * resolve.c (gfc_resolve_iterator): Use `gfc_check_vardef_context'.
        (remove_last_array_ref): New method.
        (resolve_deallocate_expr), (resolve_allocate_expr): Ditto.
        (resolve_allocate_deallocate): Ditto (for STAT and ERRMSG).
        (resolve_assoc_var): Remove checks for definability here.
        (resolve_select_type): Handle resolving of code->block here.
        (resolve_ordinary_assign): Remove PURE check.
        (resolve_code): Do not resolve code->blocks for SELECT TYPE here.
        Use `gfc_check_vardef_context' for assignments and pointer-assignments.

2010-09-23  Daniel Kraft  <d@domob.eu>

        PR fortran/38936
        PR fortran/44044
        PR fortran/45474
        * gfortran.dg/intrinsic_intent_1.f03: New test.
        * gfortran.dg/select_type_17.f03: New test.
        * gfortran.dg/associate_5.f03: More definability tests.
        * gfortran.dg/enum_2.f90: Check definability.
        * gfortran.dg/allocatable_dummy_2.f90: Change expected error message.
        * gfortran.dg/allocate_alloc_opt_2.f90: Ditto.
        * gfortran.dg/char_expr_2.f90: Ditto.
        * gfortran.dg/deallocate_alloc_opt_2.f90: Ditto.
        * gfortran.dg/enum_5.f90: Ditto.
        * gfortran.dg/equiv_constraint_8.f90: Ditto.
        * gfortran.dg/impure_assignment_2.f90: Ditto.
        * gfortran.dg/impure_assignment_3.f90: Ditto.
        * gfortran.dg/intent_out_1.f90: Ditto.
        * gfortran.dg/intent_out_3.f90: Ditto.
        * gfortran.dg/pointer_assign_7.f90: Ditto.
        * gfortran.dg/pointer_intent_3.f90: Ditto.
        * gfortran.dg/pr19936_1.f90: Ditto.
        * gfortran.dg/proc_ptr_comp_3.f90: Ditto.
        * gfortran.dg/simpleif_2.f90: Ditto.
        * gfortran.dg/protected_5.f90: Ditto.
        * gfortran.dg/protected_4.f90: Ditto and remove invalid error check.
        * gfortran.dg/protected_6.f90: Ditto.
        * gfortran.dg/protected_7.f90: Ditto.

Added:
    trunk/gcc/testsuite/gfortran.dg/intrinsic_intent_1.f03
    trunk/gcc/testsuite/gfortran.dg/select_type_17.f03
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/expr.c
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/interface.c
    trunk/gcc/fortran/intrinsic.c
    trunk/gcc/fortran/match.c
    trunk/gcc/fortran/primary.c
    trunk/gcc/fortran/resolve.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/allocatable_dummy_2.f90
    trunk/gcc/testsuite/gfortran.dg/allocate_alloc_opt_2.f90
    trunk/gcc/testsuite/gfortran.dg/associate_5.f03
    trunk/gcc/testsuite/gfortran.dg/char_expr_2.f90
    trunk/gcc/testsuite/gfortran.dg/deallocate_alloc_opt_2.f90
    trunk/gcc/testsuite/gfortran.dg/enum_2.f90
    trunk/gcc/testsuite/gfortran.dg/enum_5.f90
    trunk/gcc/testsuite/gfortran.dg/equiv_constraint_8.f90
    trunk/gcc/testsuite/gfortran.dg/impure_assignment_2.f90
    trunk/gcc/testsuite/gfortran.dg/impure_assignment_3.f90
    trunk/gcc/testsuite/gfortran.dg/intent_out_1.f90
    trunk/gcc/testsuite/gfortran.dg/intent_out_3.f90
    trunk/gcc/testsuite/gfortran.dg/pointer_assign_7.f90
    trunk/gcc/testsuite/gfortran.dg/pointer_intent_3.f90
    trunk/gcc/testsuite/gfortran.dg/pr19936_1.f90
    trunk/gcc/testsuite/gfortran.dg/proc_ptr_comp_3.f90
    trunk/gcc/testsuite/gfortran.dg/protected_4.f90
    trunk/gcc/testsuite/gfortran.dg/protected_5.f90
    trunk/gcc/testsuite/gfortran.dg/protected_6.f90
    trunk/gcc/testsuite/gfortran.dg/protected_7.f90
    trunk/gcc/testsuite/gfortran.dg/simpleif_2.f90


-- 


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


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

* [Bug fortran/44044] [OOP] SELECT TYPE with class-valued function
  2010-05-08 20:08 [Bug fortran/44044] New: [OOP] SELECT TYPE with class-valued function janus at gcc dot gnu dot org
                   ` (9 preceding siblings ...)
  2010-09-23  8:38 ` domob at gcc dot gnu dot org
@ 2010-09-23  8:39 ` domob at gcc dot gnu dot org
  10 siblings, 0 replies; 12+ messages in thread
From: domob at gcc dot gnu dot org @ 2010-09-23  8:39 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from domob at gcc dot gnu dot org  2010-09-23 08:39 -------
This implemented bonus feature #2 from comment #3.  Closing now.


-- 

domob at gcc dot gnu dot org changed:

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


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


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

end of thread, other threads:[~2010-09-23  8:39 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-08 20:08 [Bug fortran/44044] New: [OOP] SELECT TYPE with class-valued function janus at gcc dot gnu dot org
2010-05-08 20:14 ` [Bug fortran/44044] " janus at gcc dot gnu dot org
2010-05-08 20:20 ` janus at gcc dot gnu dot org
2010-05-08 20:23 ` janus at gcc dot gnu dot org
2010-05-09 11:55 ` janus at gcc dot gnu dot org
2010-05-10 10:06 ` burnus at gcc dot gnu dot org
2010-05-10 12:54 ` janus at gcc dot gnu dot org
2010-05-17  8:26 ` janus at gcc dot gnu dot org
2010-05-17  8:32 ` janus at gcc dot gnu dot org
2010-08-27  7:31 ` burnus at gcc dot gnu dot org
2010-09-23  8:38 ` domob at gcc dot gnu dot org
2010-09-23  8:39 ` domob at gcc dot gnu dot 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).