Quantcast
Channel: Fortran
Viewing all articles
Browse latest Browse all 3108

INTENT(IN) attribute checking of pointer components in ASSOCIATE constructs

$
0
0

(This feels a bit familiar, so maybe I've seen or reported it before.)

ifort complains when the target of a pointer component of a base object with the INTENT(IN) attribute is used as the selector in an associate construct and the associate name is then is defined by argument association with an INTENT([IN]OUT) dummy argument.

PROGRAM p
  IMPLICIT NONE

  TYPE t
    INTEGER, POINTER :: ptr_comp
  END TYPE t

  INTEGER, TARGET :: a_pointer_target
  TYPE(t) :: a

  a%ptr_comp => a_pointer_target

  CALL proc(a)
CONTAINS
  SUBROUTINE proc(arg)
    TYPE(t), INTENT(IN) :: arg

    ! 6.4.2p5 A /data-ref/ with more than one /part-ref/ is a subobject of
    ! its base object if non of the /part-name/s, except for possibly the
    ! rightmost, are pointers.  If the rightmost /part-name/ is the only
    ! pointer, then the /data-ref/ is a subobject of its base object in
    ! context that pertain to its pointer association status but not in
    ! any other contexts.
    !
    ! 16.5.1.6p3: The associate name is associated with the target of the
    ! pointer...
    !
    ! See also note 5.16.
    !
    ! As x is associated with the target of the pointer, it is associated
    ! with something that is not a subobject of arg, and hence that thing
    ! does not have the INTENT(IN) attribute.
    ASSOCIATE(x => arg%ptr_comp)
      CALL define(x)    ! ifort 15.0.0 - error #6780: A dummy argument
                        ! with the INTENT(IN) attribute shall not be
                        ! defined nor become undefined.   [X]
    END ASSOCIATE
  END SUBROUTINE proc

  SUBROUTINE define(i)
    INTEGER, INTENT(OUT) :: i
    i = 6
  END SUBROUTINE define
END PROGRAM p

 

>ifort /check:all /warn:all /standard-semantics "2014-10-13 associate-intent.f90"
Intel(R) Visual Fortran Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 15.0.0.108 Build 20140726
Copyright (C) 1985-2014 Intel Corporation.  All rights reserved.

2014-10-13 associate-intent.f90(34): error #6780: A dummy argument with the INTENT(IN) attribute shall not be defined nor become undefined.   [X]
      CALL define(x)    ! ifort 15.0.0 - error #6780: A dummy argument
------------------^
compilation aborted for 2014-10-13 associate-intent.f90 (code 1)

 


Viewing all articles
Browse latest Browse all 3108

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>