<?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 Re: constructor for empty arrays in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/constructor-for-empty-arrays/m-p/1198175#M151116</link>
    <description>&lt;P&gt;This is fixed in the nightly builds here for the ifort BETA in the oneAPI HPC Toolkit.&amp;nbsp; It's still a bug in the current beta08 release of this kit.&amp;nbsp; But the nightly build which is going into the oneAPI HPC Toolkit for the next beta, beta09, has this working:&lt;/P&gt;
&lt;LI-CODE lang="none"&gt;rwgreen:~/quad/u1198085$ module load comp/nightlybuild
rwgreen:~/quad/u1198085$ ifort -O0 -what -o repro repro.f90
 Intel(R) Fortran 2021.1-1898
rwgreen@orcsle156:~/quad/u1198085$ ./repro
 number of vehicles in foo =            0 ; expected is 0.


rwgreen:~/quad/u1198085$ cat repro.f90
module vehicle_module
   type :: vehicle_type
   end type
end module
module v_q_module
   use vehicle_module
   implicit none
   private

   type :: node_type
      class(vehicle_type), allocatable :: v
   end type node_type

   type, public :: q_type
      private
      type(node_type), dimension(:), allocatable :: vehicles
   contains
      procedure :: empty, get_num_vehicles
   end type q_type
contains
   subroutine empty(q)
      class(q_type), intent(out) :: q
      q%vehicles = [ node_type :: ] 
   end subroutine empty
   function get_num_vehicles(q) result(num)
      class(q_type), intent(in) :: q
      integer :: num
      num = 0
      if ( allocated(q%vehicles) ) num = size(q%vehicles)
   end function
end module v_q_module

   use v_q_module
   type(q_type) :: foo
   call foo%empty()
   print *, "number of vehicles in foo = ", foo%get_num_vehicles(), "; expected is 0."
end&lt;/LI-CODE&gt;</description>
    <pubDate>Fri, 07 Aug 2020 02:57:10 GMT</pubDate>
    <dc:creator>Ron_Green</dc:creator>
    <dc:date>2020-08-07T02:57:10Z</dc:date>
    <item>
      <title>constructor for empty arrays</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/constructor-for-empty-arrays/m-p/1198058#M151107</link>
      <description>&lt;P&gt;I am working on an example using classes from the Guide to Fortran 2008 Programming.&amp;nbsp; I want to see if classes will help in what I am trying to do.&amp;nbsp; I have worked with classes in other languages .&lt;/P&gt;
&lt;P&gt;Here is the part of the code that I get an error from.&lt;/P&gt;
&lt;P&gt;module v_q_module&lt;BR /&gt;use vehicle_module&lt;BR /&gt;implicit none&lt;BR /&gt;private&lt;BR /&gt;&lt;BR /&gt;type :: node_type&lt;BR /&gt;class(vehicle_type), allocatable :: v&lt;BR /&gt;end type node_type&lt;BR /&gt;&lt;BR /&gt;type, public :: q_type&lt;BR /&gt;private&lt;BR /&gt;type(node_type), dimension(:), allocatable :: vehicles&lt;BR /&gt;contains&lt;BR /&gt;procedure :: empty, is_empty, insert, remove, print_licenses&lt;BR /&gt;end type q_type&lt;BR /&gt;contains&lt;BR /&gt;subroutine empty(q)&lt;BR /&gt;class(q_type), intent(out) :: q&lt;BR /&gt;q%vehicles = [ node_type :: ]&lt;BR /&gt;end subroutine empty&lt;BR /&gt;end module v_q_module&lt;/P&gt;
&lt;P&gt;The error is the following:&lt;/P&gt;
&lt;P&gt;C:\Michael\traffic_simulation\traffic_simulation\module2.f90(19): error #5082: Syntax error, found '::' when expecting one of: , : (/ ]&lt;BR /&gt;C:\Michael\traffic_simulation\traffic_simulation\module2.f90(19): error #6478: A type-name must not be used as a variable. [NODE_TYPE]&lt;BR /&gt;compilation aborted for C:\Michael\traffic_simulation\traffic_simulation\module2.f90 (code 1)&lt;/P&gt;
&lt;P&gt;All the reading I have done tells me that this line should be a valid statement.&lt;/P&gt;
&lt;P&gt;q%vehicles = [ node_type :: ]&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;
&lt;P&gt;Michael&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Aug 2020 17:59:57 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/constructor-for-empty-arrays/m-p/1198058#M151107</guid>
      <dc:creator>kolber__Michael</dc:creator>
      <dc:date>2020-08-06T17:59:57Z</dc:date>
    </item>
    <item>
      <title>Re: constructor for empty arrays</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/constructor-for-empty-arrays/m-p/1198071#M151108</link>
      <description>&lt;P&gt;It is a bug in Intel Fortran compiler, please submit a support request if you can at Intel Online Service Center.&lt;/P&gt;
&lt;P&gt;A couple of suggestions:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Try another compiler or two if you can to guide your learning of modern Fortran e.g., open-source gfortran (&lt;A href="https://gcc.gnu.org/wiki/GFortran" target="_blank"&gt;https://gcc.gnu.org/wiki/GFortran&lt;/A&gt;) and if possible, another commercial compiler - see point 2,&lt;/LI&gt;
&lt;LI&gt;Consider participating in Fortran language discourse at&amp;nbsp;&lt;A href="https://fortran-lang.discourse.group/" target="_blank" rel="noopener"&gt;https://fortran-lang.discourse.group/&lt;/A&gt;.&amp;nbsp; where you can find more options and resources re: Fortran and other compilers, etc..&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Note this variant below of your code in the original post.&amp;nbsp; It works as I expect using gfortran:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="fortran"&gt;module vehicle_module
   type :: vehicle_type
   end type
end module
module v_q_module
   use vehicle_module
   implicit none
   private

   type :: node_type
      class(vehicle_type), allocatable :: v
   end type node_type

   type, public :: q_type
      private
      type(node_type), dimension(:), allocatable :: vehicles
   contains
      procedure :: empty, get_num_vehicles
   end type q_type
contains
   subroutine empty(q)
      class(q_type), intent(out) :: q
      q%vehicles = [ node_type :: ]
   end subroutine empty
   function get_num_vehicles(q) result(num)
      class(q_type), intent(in) :: q
      integer :: num
      num = 0
      if ( allocated(q%vehicles) ) num = size(q%vehicles)
   end function
end module v_q_module

   use v_q_module
   type(q_type) :: foo
   call foo%empty()
   print *, "number of vehicles in foo = ", foo%get_num_vehicles(), "; expected is 0."
end
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="none"&gt; number of vehicles in foo =            0 ; expected is 0.&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Aug 2020 18:55:15 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/constructor-for-empty-arrays/m-p/1198071#M151108</guid>
      <dc:creator>FortranFan</dc:creator>
      <dc:date>2020-08-06T18:55:15Z</dc:date>
    </item>
    <item>
      <title>Re: constructor for empty arrays</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/constructor-for-empty-arrays/m-p/1198079#M151110</link>
      <description>&lt;P&gt;FortranFan,&lt;/P&gt;
&lt;P&gt;Thanks for the advice.&amp;nbsp; I would have to do the extra stuff at home.&amp;nbsp; We are bound to the Intel complier at work.&amp;nbsp; This project is something that I am doing to make a contribution at work when I do not have an upgrade project for the current application.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Aug 2020 19:16:52 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/constructor-for-empty-arrays/m-p/1198079#M151110</guid>
      <dc:creator>kolber__Michael</dc:creator>
      <dc:date>2020-08-06T19:16:52Z</dc:date>
    </item>
    <item>
      <title>Re: constructor for empty arrays</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/constructor-for-empty-arrays/m-p/1198090#M151111</link>
      <description>&lt;P&gt;I remember reporting a similar bug a long time ago. I wonder what's different about this case?&lt;/P&gt;</description>
      <pubDate>Thu, 06 Aug 2020 21:36:26 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/constructor-for-empty-arrays/m-p/1198090#M151111</guid>
      <dc:creator>Steve_Lionel</dc:creator>
      <dc:date>2020-08-06T21:36:26Z</dc:date>
    </item>
    <item>
      <title>Re: constructor for empty arrays</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/constructor-for-empty-arrays/m-p/1198121#M151112</link>
      <description>&lt;P&gt;The passing of roughly eight years!&lt;/P&gt;</description>
      <pubDate>Thu, 06 Aug 2020 22:20:09 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/constructor-for-empty-arrays/m-p/1198121#M151112</guid>
      <dc:creator>IanH</dc:creator>
      <dc:date>2020-08-06T22:20:09Z</dc:date>
    </item>
    <item>
      <title>Re: constructor for empty arrays</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/constructor-for-empty-arrays/m-p/1198122#M151113</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="none"&gt;&lt;a href="https://community.intel.com/t5/user/viewprofilepage/user-id/83145"&gt;@kolber__Michael&lt;/a&gt; wrote:

.. We are bound to the Intel complier at work.  This project is something that
I am doing to make a contribution at work when I do not have an upgrade
project for the current application&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can consider a workaround based on an "original" facility in Fortran for dynamic memory i.e., the ALLOCATE statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="fortran"&gt;allocate( q%vehicles(0) )&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Aug 2020 22:30:58 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/constructor-for-empty-arrays/m-p/1198122#M151113</guid>
      <dc:creator>FortranFan</dc:creator>
      <dc:date>2020-08-06T22:30:58Z</dc:date>
    </item>
    <item>
      <title>Re: constructor for empty arrays</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/constructor-for-empty-arrays/m-p/1198175#M151116</link>
      <description>&lt;P&gt;This is fixed in the nightly builds here for the ifort BETA in the oneAPI HPC Toolkit.&amp;nbsp; It's still a bug in the current beta08 release of this kit.&amp;nbsp; But the nightly build which is going into the oneAPI HPC Toolkit for the next beta, beta09, has this working:&lt;/P&gt;
&lt;LI-CODE lang="none"&gt;rwgreen:~/quad/u1198085$ module load comp/nightlybuild
rwgreen:~/quad/u1198085$ ifort -O0 -what -o repro repro.f90
 Intel(R) Fortran 2021.1-1898
rwgreen@orcsle156:~/quad/u1198085$ ./repro
 number of vehicles in foo =            0 ; expected is 0.


rwgreen:~/quad/u1198085$ cat repro.f90
module vehicle_module
   type :: vehicle_type
   end type
end module
module v_q_module
   use vehicle_module
   implicit none
   private

   type :: node_type
      class(vehicle_type), allocatable :: v
   end type node_type

   type, public :: q_type
      private
      type(node_type), dimension(:), allocatable :: vehicles
   contains
      procedure :: empty, get_num_vehicles
   end type q_type
contains
   subroutine empty(q)
      class(q_type), intent(out) :: q
      q%vehicles = [ node_type :: ] 
   end subroutine empty
   function get_num_vehicles(q) result(num)
      class(q_type), intent(in) :: q
      integer :: num
      num = 0
      if ( allocated(q%vehicles) ) num = size(q%vehicles)
   end function
end module v_q_module

   use v_q_module
   type(q_type) :: foo
   call foo%empty()
   print *, "number of vehicles in foo = ", foo%get_num_vehicles(), "; expected is 0."
end&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 07 Aug 2020 02:57:10 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/constructor-for-empty-arrays/m-p/1198175#M151116</guid>
      <dc:creator>Ron_Green</dc:creator>
      <dc:date>2020-08-07T02:57:10Z</dc:date>
    </item>
  </channel>
</rss>

