<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Generic type bound assignment with polymorphic variables in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Generic-type-bound-assignment-with-polymorphic-variables/m-p/803162#M38807</link>
    <description>Steve,&lt;BR /&gt;I found the error in what I sent you earlier. Consider the following:&lt;BR /&gt;&lt;BR /&gt;!=====================================================&lt;BR /&gt;module a_module&lt;BR /&gt;
 implicit none&lt;BR /&gt;
 private&lt;BR /&gt;
 public :: a_t&lt;BR /&gt;
&lt;BR /&gt;

 type a_t&lt;BR /&gt;

 contains&lt;BR /&gt;

 procedure, public :: assign&lt;BR /&gt;

 generic :: assignment(=) =&amp;gt; assign&lt;BR /&gt;

 end type a_t&lt;BR /&gt;
&lt;BR /&gt;
 contains&lt;BR /&gt;
&lt;BR /&gt;
 subroutine assign(to, from)&lt;BR /&gt;
 class(a_t), intent(inout) :: to&lt;BR /&gt;
 class(a_t), intent(in) :: from&lt;BR /&gt;
&lt;BR /&gt;
 end subroutine assign&lt;BR /&gt;
&lt;BR /&gt;
end module a_module&lt;BR /&gt;
&lt;BR /&gt;module b_module&lt;BR /&gt; use a_module&lt;BR /&gt;
 implicit none&lt;BR /&gt;
 private&lt;BR /&gt;
 public :: b_t&lt;BR /&gt;
&lt;BR /&gt;

 type, extends(a_t) :: b_t&lt;BR /&gt;

 contains&lt;BR /&gt;

 procedure, public :: assign&lt;BR /&gt;

 end type b_t&lt;BR /&gt;
&lt;BR /&gt;
 contains&lt;BR /&gt;
&lt;BR /&gt;
 subroutine assign(to, from)&lt;BR /&gt;
 class(b_t), intent(inout) :: to&lt;BR /&gt;
 class(a_t), intent(in) :: from ! Previous error: needs to be of the same type as the overridden procedure&lt;BR /&gt;
&lt;BR /&gt;
 end subroutine assign&lt;BR /&gt;
&lt;BR /&gt;
end module b_module&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;program main&lt;BR /&gt;&lt;BR /&gt;use a_module&lt;BR /&gt;use b_module&lt;BR /&gt;&lt;BR /&gt;implicit none&lt;BR /&gt;&lt;BR /&gt;class(a_t), allocatable :: v1&lt;BR /&gt;class(a_t), allocatable :: v2&lt;BR /&gt;&lt;BR /&gt;allocate(b_t::v1)&lt;BR /&gt;allocate(b_t::v2)&lt;BR /&gt;&lt;BR /&gt;call v2%assign(v1)&lt;BR /&gt;v2 = v1&lt;BR /&gt;&lt;BR /&gt;end program&lt;BR /&gt;!=====================================================&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;As per the comment, the "from" dummy argument needs to be of the same type as the overridden procedure.&lt;BR /&gt;&lt;BR /&gt;The code now compiles, but the resulting performance doesn't seem to be correct. I would expect that the two lines "call v2%assign(v1)" and "v2 = v1" would execute the same procedure (the b_t type-bound procedure "assign"). The first line does this; the second executes the a_t "assign" function.&lt;BR /&gt;</description>
    <pubDate>Thu, 03 Nov 2011 17:01:07 GMT</pubDate>
    <dc:creator>dougf</dc:creator>
    <dc:date>2011-11-03T17:01:07Z</dc:date>
    <item>
      <title>Generic type bound assignment with polymorphic variables</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Generic-type-bound-assignment-with-polymorphic-variables/m-p/803160#M38805</link>
      <description>Using Release 7 of version 12.1, I'm trying to define a generic assignment function for a polymorphic variable. The following code demonstrates a couple of problems I'm having:&lt;BR /&gt;&lt;BR /&gt;!=====================================================&lt;BR /&gt;module a_module&lt;BR /&gt;
 implicit none&lt;BR /&gt;
 private&lt;BR /&gt;
 public :: a_t&lt;BR /&gt;
&lt;BR /&gt;

 type a_t&lt;BR /&gt;

 contains&lt;BR /&gt;

 procedure, public :: assign&lt;BR /&gt;

 generic :: assignment(=) =&amp;gt; assign&lt;BR /&gt;

 end type a_t&lt;BR /&gt;
&lt;BR /&gt;
 contains&lt;BR /&gt;
&lt;BR /&gt;
 subroutine assign(to, from)&lt;BR /&gt;
 class(a_t), intent(inout) :: to&lt;BR /&gt;
 class(a_t), intent(in) :: from&lt;BR /&gt;
&lt;BR /&gt;
 end subroutine assign&lt;BR /&gt;
&lt;BR /&gt;
end module a_module&lt;BR /&gt;
&lt;BR /&gt;module b_module&lt;BR /&gt; use a_module&lt;BR /&gt;
 implicit none&lt;BR /&gt;
 private&lt;BR /&gt;
 public :: b_t&lt;BR /&gt;
&lt;BR /&gt;

 type, extends(a_t) :: b_t&lt;BR /&gt;

 contains&lt;BR /&gt;

 procedure, public :: assign&lt;BR /&gt;

 generic :: assignment(=) =&amp;gt; assign&lt;BR /&gt;

 end type a_t&lt;BR /&gt;
&lt;BR /&gt;
 contains&lt;BR /&gt;
&lt;BR /&gt;
 subroutine assign(to, from)&lt;BR /&gt;
 class(b_t), intent(inout) :: to&lt;BR /&gt;
 class(b_t), intent(in) :: from&lt;BR /&gt;
&lt;BR /&gt;
 end subroutine assign&lt;BR /&gt;
&lt;BR /&gt;
end module b_module&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;program main&lt;BR /&gt;&lt;BR /&gt;use a_module&lt;BR /&gt;use b_module&lt;BR /&gt;&lt;BR /&gt;implicit none&lt;BR /&gt;&lt;BR /&gt;class(a_t), allocatable :: v1&lt;BR /&gt;class(a_t), allocatable :: v2&lt;BR /&gt;&lt;BR /&gt;allocate(b_t::v1)&lt;BR /&gt;allocate(b_t::v2)&lt;BR /&gt;&lt;BR /&gt;v2 = v1&lt;BR /&gt;&lt;BR /&gt;end program&lt;BR /&gt;!=====================================================&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;The code as-is does not compile, giving me an error 8383. Shouldn't the code work as written?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;If I change the name of the "assign" subroutine in b_module to something else (say, "assignb"), the code compiles and runs. However, when it reaches the statement "v2 = v1", it executes the subroutine assign in a_module. I would expect it to execute assignb in b_module. Is this behavior expected?&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Doug&lt;BR /&gt;</description>
      <pubDate>Fri, 28 Oct 2011 17:34:56 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Generic-type-bound-assignment-with-polymorphic-variables/m-p/803160#M38805</guid>
      <dc:creator>dougf</dc:creator>
      <dc:date>2011-10-28T17:34:56Z</dc:date>
    </item>
    <item>
      <title>Generic type bound assignment with polymorphic variables</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Generic-type-bound-assignment-with-polymorphic-variables/m-p/803161#M38806</link>
      <description>I can reproduce this - once I correct the typo in the declaration of b_t. The second problem, where it calls the a_t assignment, is I think one I've seen before, though I thought we had fixed it. I will check. I need to study the standard a bit before I comment on the first problem (error 8383).</description>
      <pubDate>Fri, 28 Oct 2011 19:49:38 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Generic-type-bound-assignment-with-polymorphic-variables/m-p/803161#M38806</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2011-10-28T19:49:38Z</dc:date>
    </item>
    <item>
      <title>Generic type bound assignment with polymorphic variables</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Generic-type-bound-assignment-with-polymorphic-variables/m-p/803162#M38807</link>
      <description>Steve,&lt;BR /&gt;I found the error in what I sent you earlier. Consider the following:&lt;BR /&gt;&lt;BR /&gt;!=====================================================&lt;BR /&gt;module a_module&lt;BR /&gt;
 implicit none&lt;BR /&gt;
 private&lt;BR /&gt;
 public :: a_t&lt;BR /&gt;
&lt;BR /&gt;

 type a_t&lt;BR /&gt;

 contains&lt;BR /&gt;

 procedure, public :: assign&lt;BR /&gt;

 generic :: assignment(=) =&amp;gt; assign&lt;BR /&gt;

 end type a_t&lt;BR /&gt;
&lt;BR /&gt;
 contains&lt;BR /&gt;
&lt;BR /&gt;
 subroutine assign(to, from)&lt;BR /&gt;
 class(a_t), intent(inout) :: to&lt;BR /&gt;
 class(a_t), intent(in) :: from&lt;BR /&gt;
&lt;BR /&gt;
 end subroutine assign&lt;BR /&gt;
&lt;BR /&gt;
end module a_module&lt;BR /&gt;
&lt;BR /&gt;module b_module&lt;BR /&gt; use a_module&lt;BR /&gt;
 implicit none&lt;BR /&gt;
 private&lt;BR /&gt;
 public :: b_t&lt;BR /&gt;
&lt;BR /&gt;

 type, extends(a_t) :: b_t&lt;BR /&gt;

 contains&lt;BR /&gt;

 procedure, public :: assign&lt;BR /&gt;

 end type b_t&lt;BR /&gt;
&lt;BR /&gt;
 contains&lt;BR /&gt;
&lt;BR /&gt;
 subroutine assign(to, from)&lt;BR /&gt;
 class(b_t), intent(inout) :: to&lt;BR /&gt;
 class(a_t), intent(in) :: from ! Previous error: needs to be of the same type as the overridden procedure&lt;BR /&gt;
&lt;BR /&gt;
 end subroutine assign&lt;BR /&gt;
&lt;BR /&gt;
end module b_module&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;program main&lt;BR /&gt;&lt;BR /&gt;use a_module&lt;BR /&gt;use b_module&lt;BR /&gt;&lt;BR /&gt;implicit none&lt;BR /&gt;&lt;BR /&gt;class(a_t), allocatable :: v1&lt;BR /&gt;class(a_t), allocatable :: v2&lt;BR /&gt;&lt;BR /&gt;allocate(b_t::v1)&lt;BR /&gt;allocate(b_t::v2)&lt;BR /&gt;&lt;BR /&gt;call v2%assign(v1)&lt;BR /&gt;v2 = v1&lt;BR /&gt;&lt;BR /&gt;end program&lt;BR /&gt;!=====================================================&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;As per the comment, the "from" dummy argument needs to be of the same type as the overridden procedure.&lt;BR /&gt;&lt;BR /&gt;The code now compiles, but the resulting performance doesn't seem to be correct. I would expect that the two lines "call v2%assign(v1)" and "v2 = v1" would execute the same procedure (the b_t type-bound procedure "assign"). The first line does this; the second executes the a_t "assign" function.&lt;BR /&gt;</description>
      <pubDate>Thu, 03 Nov 2011 17:01:07 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Generic-type-bound-assignment-with-polymorphic-variables/m-p/803162#M38807</guid>
      <dc:creator>dougf</dc:creator>
      <dc:date>2011-11-03T17:01:07Z</dc:date>
    </item>
    <item>
      <title>Generic type bound assignment with polymorphic variables</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Generic-type-bound-assignment-with-polymorphic-variables/m-p/803163#M38808</link>
      <description>Yes, I see this behavior. We'll look into it and get back to you.</description>
      <pubDate>Thu, 03 Nov 2011 17:07:36 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Generic-type-bound-assignment-with-polymorphic-variables/m-p/803163#M38808</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2011-11-03T17:07:36Z</dc:date>
    </item>
    <item>
      <title>Generic type bound assignment with polymorphic variables</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Generic-type-bound-assignment-with-polymorphic-variables/m-p/803164#M38809</link>
      <description>Sorry for the delay - I have escalated this as issue DPD200175845. The compiler is using the "declared type" of v1 and v2 rather than the dynamic type.&lt;BR /&gt;&lt;BR /&gt;I believe the error message for the original code is correct, since you give the routines the same name. Here is a modified version of the code which shows how this sort of thing is supposed to be done, though it still doesn't do what is wanted.&lt;BR /&gt;&lt;BR /&gt;&lt;PRE&gt;[fortran]module a_module
  implicit none
  private
  public :: a_t

  type a_t
    contains
      procedure, public :: assign_a
      generic :: assignment(=) =&amp;gt; assign_a
  end type a_t

  contains

  subroutine assign_a(to, from)
    class(a_t), intent(inout) :: to
    class(a_t), intent(in) :: from
    print *, "In assign_a"
  end subroutine assign_a

end module a_module

module b_module
  use a_module
  implicit none
  private
  public :: b_t

  type, extends(a_t) :: b_t
    contains
      procedure, public :: assign_b
      generic :: assignment(=) =&amp;gt; assign_b
  end type b_t

  contains

  subroutine assign_b(to, from)
    class(b_t), intent(inout) :: to
    class(b_t), intent(in) :: from   
    print *, "In assign_b"

  end subroutine assign_b

end module b_module


program main

use a_module
use b_module

implicit none

class(a_t), allocatable :: v1
class(a_t), allocatable :: v2

allocate(b_t::v1)
allocate(b_t::v2)

v2 = v1

end program
[/fortran]&lt;/PRE&gt; &lt;BR /&gt;</description>
      <pubDate>Fri, 11 Nov 2011 21:42:29 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Generic-type-bound-assignment-with-polymorphic-variables/m-p/803164#M38809</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2011-11-11T21:42:29Z</dc:date>
    </item>
    <item>
      <title>Hi Steve. I have a similar</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Generic-type-bound-assignment-with-polymorphic-variables/m-p/803165#M38810</link>
      <description>Hi Steve. I have a similar question (see: &lt;A href="http://software.intel.com/en-us/forums/topic/328732#comment-1681634)" target="_blank"&gt;http://software.intel.com/en-us/forums/topic/328732#comment-1681634)&lt;/A&gt; I see that the dereferencing of assignment based on declared type is standard-conforming. But is there another way of implementing a generic container which would be able to add values to storage from the declared class or any of its subclasses?

Thanks

Evgeniy</description>
      <pubDate>Tue, 09 Oct 2012 07:54:28 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Generic-type-bound-assignment-with-polymorphic-variables/m-p/803165#M38810</guid>
      <dc:creator>Evgeny_Shapiro</dc:creator>
      <dc:date>2012-10-09T07:54:28Z</dc:date>
    </item>
  </channel>
</rss>

