Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29282 Discussions

Derived type pointer components and intent(in) are out?

Steven_L_Intel1
Employee
565 Views
Moved from separate thread as it's a new issue.
0 Kudos
2 Replies
IanH
Honored Contributor III
565 Views
Not quite there yet.

[fortran]MODULE TheUpdateGivethAndTheUpdateTakethAway
  IMPLICIT NONE
  
  TYPE :: Parent
    INTEGER :: a
  END TYPE Parent
  
  TYPE, EXTENDS(PARENT) :: Extension
    INTEGER :: b
  END TYPE Extension
  
  TYPE HasDefinedAssignment
    INTEGER :: c
  END TYPE HasDefinedAssignment
  
  TYPE Container
    TYPE(Parent), POINTER :: ptr_comp
    CLASS(Parent), POINTER :: poly_ptr_comp
    TYPE(HasDefinedAssignment), POINTER :: da_ptr_comp
  END TYPE Container  

  INTERFACE ASSIGNMENT(=)
    MODULE PROCEDURE defined_assignment
  END INTERFACE ASSIGNMENT(=)
CONTAINS
  SUBROUTINE ThisAlwaysWorked(arg)
    TYPE(Container), INTENT(IN) :: arg
    !****
    arg%ptr_comp%a = 1
  END SUBROUTINE ThisAlwaysWorked

  SUBROUTINE ThisIsStillBroken(arg)
    TYPE(Container), INTENT(IN) :: arg
    !****
    arg%da_ptr_comp = 2
  END SUBROUTINE ThisIsStillBroken
    
  SUBROUTINE ThisNowWorkswith_12_0_3(arg)
    TYPE(Container), INTENT(IN) :: arg
    !****
    CALL modify_a_parent(arg%ptr_comp)
  END SUBROUTINE ThisNowWorkswith_12_0_3
  
  SUBROUTINE ThePreviousWorkAroundIsStillOk(arg)
    TYPE(Container), INTENT(IN) :: arg
    TYPE(Parent), POINTER :: p
    !****
    p => arg%ptr_comp
    CALL modify_a_parent(p)
  END SUBROUTINE ThePreviousWorkAroundIsStillOk
  
  SUBROUTINE But_12_0_3_BrokeThis(arg)
    TYPE(Container), INTENT(IN) :: arg
    !****
    SELECT TYPE (s => arg%poly_ptr_comp)
    TYPE IS (Extension)
      s%b = 1
    END SELECT
  END SUBROUTINE But_12_0_3_BrokeThis

  SUBROUTINE TheWorkAroundIsStillOk(arg)
    TYPE(Container), INTENT(IN) :: arg
    CLASS(Parent), POINTER :: p
    !****
    p => arg%poly_ptr_comp
    SELECT TYPE (p)
    TYPE IS (Extension)
      p%b = 1
    END SELECT
  END SUBROUTINE TheWorkAroundIsStillOk
  
  SUBROUTINE defined_assignment(lhs, rhs)
    TYPE(HasDefinedAssignment), INTENT(OUT) :: lhs
    INTEGER, INTENT(IN) :: rhs
    !****
    lhs%c = rhs
  END SUBROUTINE defined_assignment
  
  SUBROUTINE modify_a_parent(parent_arg)
    TYPE(Parent), INTENT(OUT) :: parent_arg
    !****
    parent_arg%a = 1
  END SUBROUTINE modify_a_parent
END MODULE TheUpdateGivethAndTheUpdateTakethAway
[/fortran]


[plain]>ifort /c /warn:all /check:all PointerIntentTest.f90
Intel Visual Fortran Compiler XE for applications running on IA-32, Version 12.0.3.175 Build 20110309
Copyright (C) 1985-2011 Intel Corporation.  All rights reserved.

PointerIntentTest.f90(35): error #6780: A dummy argument with the INTENT(IN) attribute shall not be defined nor become undefined.   [ARG]
    arg%da_ptr_comp = 2
----^
PointerIntentTest.f90(57): error #6780: A dummy argument with the INTENT(IN) attribute shall not be defined nor become undefined.   
      s%b = 1
------^
compilation aborted for PointerIntentTest.f90 (code 1)[/plain]
0 Kudos
Steven_L_Intel1
Employee
565 Views
Thanks - we'll take a look at this.
0 Kudos
Reply