User account creation filtered due to spam.

Bug 52270 - [OOP] Polymorphic vars: wrong intent(in) check, passing nonptr variable to intent(in) ptr dummy
Summary: [OOP] Polymorphic vars: wrong intent(in) check, passing nonptr variable to in...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: 4.8.0
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2012-02-16 07:48 UTC by Tobias Burnus
Modified: 2016-11-16 15:02 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2012-02-16 07:48:23 UTC
From http://j3-fortran.org/doc/meeting/197/12-131.txt

The following program is rejected with:
-----------------------------------------------------
      p%c = 3
      1
Error: Dummy argument 'p' with INTENT(IN) in variable definition context (assignment) at (1)

    Call s(x)
           1
Error: Actual argument to 'p' at (1) must be polymorphic
-----------------------------------------------------

The first item is bogus as 'p' is a pointer and pointer intents only affect the pointer association status. Something must go wrong with regards to polymorphic types.


The second error is formally correct, but the quoted interpretation request by Malcolm Cohen suggests to make it valid; that would be consistent with the Fortran 2008 changes regarding "pointer,intent(in)". One could consider to defer this part until it has passed J3 (or even WG3) voting.


  Program m013
    Type t
      Real c
    End Type
    Type(t),Target :: x
    Call s(x)
    Print *,x%c
  Contains
    Subroutine s(p)
      Class(t),Pointer,Intent(In) :: p
      p%c = 3
    End Subroutine
  End Program
Comment 1 Tobias Burnus 2012-02-16 09:54:51 UTC
Untested patch for both issues.

--- a/gcc/fortran/expr.c
+++ b/gcc/fortran/expr.c
@@ -4650,3 +4650,4 @@ gfc_check_vardef_context (gfc_expr* e, bool pointer, bool alloc_obj,
   check_intentin = true;
-  ptr_component = sym->attr.pointer;
+  ptr_component = (sym->ts.type == BT_CLASS)
+                 ? CLASS_DATA (sym)->attr.class_pointer : sym->attr.pointer;
   for (ref = e->ref; ref && check_intentin; ref = ref->next)
--- a/gcc/fortran/interface.c
+++ b/gcc/fortran/interface.c
@@ -1708,5 +1708,6 @@ compare_parameter (gfc_symbol *formal, gfc_expr *actual,

-  /* F2008, 12.5.2.5.  */
+  /* F2008, 12.5.2.5; IR F08/0073.  */
   if (formal->ts.type == BT_CLASS
-      && (CLASS_DATA (formal)->attr.class_pointer
+      && ((CLASS_DATA (formal)->attr.class_pointer
+          && !formal->attr.intent == INTENT_IN)
           || CLASS_DATA (formal)->attr.allocatable))
Comment 2 Tobias Burnus 2012-02-21 13:36:30 UTC
Submitted patch, pending review:
  http://gcc.gnu.org/ml/fortran/2012-02/msg00085.html
Comment 3 Tobias Burnus 2012-03-02 13:07:55 UTC
Author: burnus
Date: Fri Mar  2 13:07:46 2012
New Revision: 184784

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=184784
Log:
2012-03-02  Tobias Burnus  <burnus@net-b.de>

        PR fortran/52270
        * expr.c (gfc_check_vardef_context): Fix check for
        intent-in polymorphic pointer .
        * interface.c (compare_parameter): Allow passing TYPE to
        intent-in polymorphic pointer.

2012-03-02  Tobias Burnus  <burnus@net-b.de>

        PR fortran/52270
        * gfortran.dg/class_51.f90: New.


Added:
    trunk/gcc/testsuite/gfortran.dg/class_51.f90
    trunk/gcc/testsuite/gfortran.dg/class_52.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/expr.c
    trunk/gcc/fortran/interface.c
    trunk/gcc/testsuite/ChangeLog
Comment 4 Tobias Burnus 2012-03-02 13:35:13 UTC
FIXED on the trunk (i.e. GCC 4.8).